New Posts New Posts RSS Feed: NullReferenceException, DatasourceKeyName, EntityManager DataSourceResolver
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

NullReferenceException, DatasourceKeyName, EntityManager DataSourceResolver

 Post Reply Post Reply
Author
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Topic: NullReferenceException, DatasourceKeyName, EntityManager DataSourceResolver
    Posted: 15-Mar-2012 at 1:01am
Hi,
 
This got to do with EntityManager's DataSourceResolver.DataSourceKeyNames being empty on startup.
 
System.NullReferenceException: Object reference not set to an instance of an object. at IdeaBlade.EntityModel.DataSourceResolver.GetDataSourceKey(Type entityType) at IdeaBlade.EntityModel.EntityManager.CreateEntityGroupAndInitialize(Type entityType) at IdeaBlade.EntityModel.EntityManager.GetEntityGroup(Type entityType)
 
Just do the following:
 
SomeDomainModelEntityManager em = new SomeDomainModelEntityManager();
em.GetEntityGroup(typeof(SomeNonExistentTypeInDomainModel)); // throws NullReferenceException
StoredProcQuery query = new StoredProcQuery(typeof(int), "DummyNonExistentSP");
em.ExecuteQuery(query); // throws NullReferenceException
 
Not sure if this is expected, even if it is, the exception type really not helpful.
 
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 15-Mar-2012 at 12:47pm
Hi sebma,

Thank you for the feedback. It is expected but you're correct in that the exception message is not helpful. I'll file a bug report for this.

In the meantime, could you post the definition of your SomeNonExistentTypeInDomainModel?
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 15-Mar-2012 at 5:58pm
Just to clarify the following code:

StoredProcQuery query = new StoredProcQuery(typeof(int), "DummyNonExistentSP");
em.ExecuteQuery(query); // throws NullReferenceException

The exception thrown here is not due to the StoredProc not existing. It's due to its DataSourceKeyName being null. Below are working and non working examples.

StoredProcQuery query1 = new StoredProcQuery(typeof(int), "ExistingSpInYourModel");
em.ExecuteQuery(query1); //Throws NullRefException - DataSourceKeyName not set

StoredProcQuery query2 = new StoredProcQuery(typeof(int), "DummyNonExistentSP");
query2.DataSourceKeyName = "YourDsKeyHere"; //DataSourceKeyName is set but........
em.ExecuteQuery(query2); //Throws System.InvalidOperationException: The FunctionImport could not be found

StoredProcQuery query3 = new StoredProcQuery(typeof(int), "ExistingSpInYourModel");
query3.DataSourceKeyName = "YourDsKeyHere";
em.ExecuteQuery(query3); //Now this works.
Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Posted: 15-Mar-2012 at 7:29pm
SomeNonExistentTypeInDomainModel - is just any class in your project, like String, which is one of those concrete entity class.
 
Fact is, it seems as long as no query or save operation is made via EntityManager, the DataSourceKeyName could be null, which is dangerous.
 
Thanks for your clarifications.
-Seb
Back to Top
sebma View Drop Down
Groupie
Groupie
Avatar

Joined: 19-Aug-2008
Location: Singapore
Posts: 66
Post Options Post Options   Quote sebma Quote  Post ReplyReply Direct Link To This Post Posted: 15-Mar-2012 at 7:30pm
Typo Correction:
SomeNonExistentTypeInDomainModel - is just any class in your project, like String, which is NOT one of those concrete entity classes.
Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 715
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 21-Mar-2012 at 7:27pm
Thanks for the clarifications sebma. This defect has been fixed and will be included in 6.1.7 release.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down