New Posts New Posts RSS Feed: FirstOrNullEntity and metadata issue
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

FirstOrNullEntity and metadata issue

 Post Reply Post Reply
Author
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Topic: FirstOrNullEntity and metadata issue
    Posted: 16-Jun-2011 at 2:13pm
I had a working WinForm application using DevForce.  I wanted to add two more entities to an existing model and have run into two issues, which may not be related.

Issue 1 - FirstOrNullEntity
When I ran this query,

        Dim ems As EntityManager_Shared = DirectCast(em, EntityManager_Shared)
        Dim item = (From queryItem In ems.efModules                    
              Where queryItem.ID = ID
              Select queryItem).FirstOrNullEntity

I got the cryptic "Public member 'FirstOrNullEntity'" not found at run time.  I am not sure how that is possible since the IntelliSense picked it up no problem.  I've seen people having this issue when they use Include(), not not something this simple.  The only thing that is "different" is this is loading much earlier on system startup than my other queries.  In this case, in the AppStart->Main.  So I'm at a lost on how to diagnose it.

Issue 2 - Model issue
I decided to work on a second entity.  So I ported another class over to use DevForce, leaving the original code unchanged.  But now, when I run the same query above, I get:

The model's metadata artifact files (csdl, msl, ssdl) are either invalid or could not be found, either as resources in an assembly or loose in the output directory.  Perhaps you have multiple assemblies containing the same metadata. Check the connection string for key 'JonasNET_Shared', which says the artifact filenames are Shared.csdl, Shared.ssdl, and Shared.msl. Do these names match the actual artifact filenames? All three root names (e.g., 'Shared') should be the same and match the edmx filename unless you changed them deliberately.

I haven't made any changes to files directly.  I looked in this folder \JonasNET.DomainModel\obj\Debug\edmxResourcesToEmbed and there are these files for my two models.
GL.csdl
GL.msl
GL.ssdl
Shared.csdl
Shared.msl
Shared.ssdl

I actually rolled back my edmx and re-added the same two tables (since they were so simple), re-compiled and got the exact same error.

Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 16-Jun-2011 at 4:39pm
Hi Randar,
 
Both problems are a bit unusual. 
 
On issue #1  - FirstOrNullEntity is a DevForce extension method defined in the IdeaBlade.EntityModel assembly.  I don't know how it could be "not found" at run time when the application compiles OK.  Is it possible that you have any assembly mis-matches - such as one version of DevForce installed (in the GAC) yet loose lib files for another DevForce version?  If you have the exception and stack trace for this that may help diagnose the problem.
 
Issue 2 - DevForce throws that message when we try to load an EF ObjectContext with the connection string provided.  That connection string comes from one of the following:  a connectionString or edmKey in the config file, or a custom IDataSourceKeyResolver.  First check that your connection string is correct - such as a typo or similar.  Those artifact files are by default compiled into the project assembly as resources.  EF will throw an error if the exact resource names shown in the connection string aren't in the assembly.  If you have a disassembler such as Reflector you can see what's actually been compiled into the assembly. 
 
If by chance you've modified the default "Metadata Artifact Processing" to use loose files, then those loose files must be in the bin folder where the executable is, and the connection string must show that it's using loose files.
 
For both problems, I would try a complete clean and rebuild of the solution, and then double-check the connection string.  If that doesn't help, please post the exception from issue 1 and your connection string.
 
Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2011 at 8:57am
Finally getting back to this after some OS issues this morning...

Issue 1
I haven't changed anything in the DevForce install.  I installed DevForce 2010 v6.1.0.0 once and only once.  Unfortunately, I can't post the exception from Issue 1, because Issue 2 is happening before/same time.

Issue 2
-Connection string has not changed.  It's under source control, so I can confirm that the files with the connection strings are unchanged from the time it worked.  No typos in there.
-Not using a custom IDataSourceKeyResolver.
-The "Metadata Artifact Processing" is set to "Embed in Output Assembly" in both edmx files.

My connection strings are (with username/password obscured):

<connectionStrings>
    <add name="JonasNET_Shared" connectionString="metadata=res://*/Shared.csdl|res://*/Shared.ssdl|res://*/Shared.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost\sqlExpress;Initial Catalog=JonasNET;Persist Security Info=True;User ID=NOTMYREALUSER;Password=NOTMYREALPASSWORD;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
    <add name="JonasNET_GL" connectionString="metadata=res://*/GL.csdl|res://*/GL.ssdl|res://*/GL.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=localhost\sqlExpress;Initial Catalog=JonasNET;Persist Security Info=True;User ID=NOTMYREALUSER;Password=NOTMYREALPASSWORD;MultipleActiveResultSets=True&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

I need to copy the assembly for to another machine that has Reflector.  So I'll take a look at that next.
Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2011 at 9:03am
So took a look at the assembly in Reflector and opened up the assembly with my domain models.  Under Resources are the following files.

GL.csdl
GL.msl
GL.ssdl
JonasNet.DomainModel.Resources.resources
Shared.csdl
Shared.msl
Shared.ssdl

So it looks fine to me.

Very confused since it really felt like I didn't do anything "abnormal".  So unless you have a better idea, I'm most likely going to take a copy of my code and start rolling back parts of it until I find the issue. :-(
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2011 at 9:51am
Also check that the connectionStrings are defined in the app.config for your executable project.  DevForce won't use the app.config in your model project at run time.
 
The debuglog generated by DevForce may also have some information, and will indicate where the config was loaded from or if a "default" config is in use.
Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2011 at 10:12am
So I did find a clue in the DebugLog.xml.

IdeaBlade.Core.Composition.PartsCatalog:LoadCatalog

Error loading assembly 'C:\TFS\JonasNET-DevForce\JonasNET.Main\bin\x86\Debug\JonasNET.Main.exe.config' for PartsCatalog: Error with file JonasNET.Main.exe.config.

So it may be having an issue with that file, which would explain why it is having an issue with the connection string.  But I'm not sure what the issue is.  As I mentioned, it hasn't changed since the last it worked.
Back to Top
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2011 at 1:32pm
OK, seems to be working now with help from kimj, which I'm grateful for.  I'll explain in case others run into the same issue.  I built my EDMX following the recommendations in here http://www.ideablade.com/WardsCorner/LargeEFModels.pdf.  I had two entities in two different EDMX files, in two different namespaces, with the same name, namely efPvxCompany.  Once I looked at the DebugLog.xml on the BOS side, it actually had this error in there.

Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'efPvxCompany'.

But this error was only visible in the full stack trace.  So to fix my issue, I renamed the entities to be efPvxCompany_Shared and efPvxCompany_GL and everything seemed to work.

So the only question I have is, is Ward's document wrong is there some other factor that I've missed?
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 17-Jun-2011 at 4:08pm
I think the specifics of Ward's document were more applicable to EF v1 and DevForce 2009.  The mapping issue here may be because the model in DF2010 is essentially POCO to the Entity Framework, and EF apparently ignores the namespace when trying to determine the mapping between a CLR type and the conceptual model.  Here's more - http://social.msdn.microsoft.com/Forums/en-NZ/adodotnetentityframework/thread/5a8ea003-c6bc-4fc6-ad2a-634f09447c49
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down