Why does the following produce a compiler error:
public interface OwnSession : ISession { }
[...]
OwnSession s = SessionFactory.OpenSession(); // compiler error (in german unfortunately)
[...]
"SessionFactory" returns a "ISession" on "OpenSession()" (NHibernate)
You should cast the result:
OwnSession s = (OwnSession) SessionFactory.OpenSession();
If OpenSession() returns an ISession type, it could be anything that implements ISession, so you have to tell the compiler you expected a OwnSession type (only if you are sure it will return that of course)
On the other hand, you could declare your variable as ISession, and continue working with that. Unless you want to use methods or properties from the OwnSession type which are not available in the ISession interface spec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With