Print Page | Close Window

dbConttext and Precompiled Views

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=4645
Printed Date: 31-Mar-2025 at 2:18am


Topic: dbConttext and Precompiled Views
Posted By: BillG
Subject: dbConttext and Precompiled Views
Date Posted: 08-Feb-2014 at 3:03pm
I have just upgraded an existing project from DevForce 2012 to 2012. I am using an EntityFactory and EntityManager and .EDMX. I want to have the ability to use precompiled views but do not require Code First. If I understand correctly I can get Precompiled Views if I have a dbContext. What is the easiest way to add a dbContext to my existing project without having to rewrite my project that uses an EntityManager object to access all my LINQ bojects?

Bill




Replies:
Posted By: DenisK
Date Posted: 11-Feb-2014 at 10:45am
Hi Bill,

You can generate precompiled views with a DB first model using a Microsoft tool called EDM Generator. See http://msdn.microsoft.com/en-us/library/bb387165.aspx for more info.


Posted By: BillG
Date Posted: 12-Feb-2014 at 5:18am
ok i followed the directions and created the views.cs and built my app. when i run it, it displays my login screen and when the user tries to log in i get the following error

An unhandled exception of type 'IdeaBlade.EntityModel.EntityServerException' occurred in IdeaBlade.EntityModel.dll

Additional information: Key 'UnionEntities': 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 'UnionEntities', which says the artifact filenames are UnionData.csdl, UnionData.ssdl, and UnionData.msl. Do these names match the actual artifact filenames? All three root names (e.g., 'UnionData') should be the same and match the edmx filename unless you changed them deliberately.

Now this might be my problem
the name of the project is DomainModel

The datasource key is UnionEntties as is the entitymanager name and entitycontaineraccess

here is my connection string
metadata=.\UnionData.csdl|.\UnionData.ssdl|.\UnionData.msl;provider=System.Data.

and here is the prebuild event command

"%windir%\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe" /nologo /language:CSharp /mode:ViewGeneration "/inssdl:$(TargetDir)UnionData.ssdl" "/incsdl:$(TargetDir)UnionData.csdl" "/inmsl:$(TargetDir)UnionData.msl" "/outviews:$(ProjectDir)UnionData.Views.cs"

What am i doing wrong here?



Posted By: BillG
Date Posted: 12-Feb-2014 at 11:12am
just to let you know i took out the prebuild command and removed the views.cs file and rebuilt the solution and it works just fine.



Posted By: DenisK
Date Posted: 14-Feb-2014 at 5:45pm
Hi Bill,

Could you confirm if you are/are not using SL? The only thing I could think of is that you had added the UnionData.Views.cs file in your DomainModel project but not link it on the SL client project.


Posted By: BillG
Date Posted: 14-Feb-2014 at 5:57pm
no it is a WPF app. My DomainModel project is linked on the client.




Posted By: BillG
Date Posted: 14-Feb-2014 at 6:06pm
do i also have put the views.cs in the client project?



Posted By: BillG
Date Posted: 14-Feb-2014 at 6:20pm
do i have to add the 3 data files to the project if i am using the precompiled views? as i said everything works fine if i take the views.cs file out and rebuild



Posted By: DenisK
Date Posted: 17-Feb-2014 at 1:06pm
Hi Bill,

You have to add the ssdl, csdl and msl resource files to your DomainModel project and set their Build Action to Embedded Resource. Then in your web.config, (assuming you have an n-tier web project), modify how you're specifying the metadata in your connection string as follows,

Metadata=res://*/DomainModel.Model.csdl|res://*/DomainModel.Model.ssdl|res://*/DomainModel.Model.msl


Posted By: BillG
Date Posted: 17-Feb-2014 at 1:36pm
Tried those additional things and no difference i still get the same error when i run the application. Now i am not using CodeFirst and I dont have the CodeFirst.app dll. Does that matter?

Bill





Posted By: BillG
Date Posted: 17-Feb-2014 at 1:56pm
Let me tell the steps i have done so far.

1. Modified the UnionData.edmx file i changed the Metadata Artifact Processing property to Copy to Output Director

2. Built the project

3. Added the following to the Pre-Build event command line

"%windir%\Microsoft.NET\Framework\v4.0.30319\EdmGen.exe" /nologo /language:CSharp /mode:ViewGeneration "/inssdl:$(TargetDir)UnionData.ssdl" "/incsdl:$(TargetDir)UnionData.csdl" "/inmsl:$(TargetDir)UnionData.msl" "/outviews:$(ProjectDir)UnionData.Views.cs"

4. Built the project

5. In my Domain Model I added the 3 files to my project. IUnionData.csdl, UnionData.msl, and UnionData.ssdl and set the Build Action of each to Embedded Resource and the Copy to output directory to do not copy

6. Added the UnionData.Views.cs to the DomainModel

7. Rebuilt the applicaiton

8. Changed my app.config. for now i am only running client server

    <add name="UnionEntities" connectionString="metadata=res://*/DomainModel.UnionData.csdl|res://*/DomainModel.UnionData.ssdl|res://*/DomainModel.UnionData.msl; />

9. Run the app. Same error

An unhandled exception of type 'IdeaBlade.EntityModel.EntityServerException' occurred in IdeaBlade.EntityModel.dll

Additional information: Key 'UnionEntities': 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 'UnionEntities', which says the artifact filenames are UnionData.csdl, UnionData.ssdl, and UnionData.msl. Do these names match the actual artifact filenames? All three root names (e.g., 'UnionData') should be the same and match the edmx filename unless you changed them deliberately.



Posted By: DenisK
Date Posted: 17-Feb-2014 at 3:44pm
At quick glance, all your steps seem to be correct.

Click on the link below to download my working WPF n-tier sample project. See if you can compare what I have with yours.

I'd also suggest that you create a separate simple solution with your model, similar to what I did here, so we can eliminate other complexities.

uploads/912/WpfApplication1.zip - uploads/912/WpfApplication1.zip


Posted By: BillG
Date Posted: 17-Feb-2014 at 4:20pm
its redirecting me to a login page.


Posted By: JoshO
Date Posted: 17-Feb-2014 at 5:54pm
Strange, I was able to download the zip without being logged in at all with all major browsers (IE, FF, Chrome). Then I did the same logged in and was successful too. I'm not sure what could be intercepting and forcing a login redirect. Just to see, try logging out and then hit the link.


Posted By: BillG
Date Posted: 17-Feb-2014 at 9:38pm
Ok i downloaded your sample and ran it and the same error. I created a new solutions and a new domain model consisting of  one entity. went through all the steps and got the same error message. i would be glad to upload both yours and mine to show you that it is not working. if i take the precompiled views out, both apps work fine.





Posted By: BillG
Date Posted: 18-Feb-2014 at 10:01am
you need to put a try and catch in ur solution and you will see it is failing.

  void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var mgr = new NorthwindIBEntities();

                var r = mgr.Customers.ToList();              //fails on this line.
            }
            catch (Exception ex)
            {
                DebugFns.WriteLine(ex.Message);
            }
        }


Posted By: DenisK
Date Posted: 18-Feb-2014 at 5:01pm
I did and I was able to verify that it's not failing. I can see in variable 'r' that I'm getting 93 customer records back. Something must be different between your environment and mine.

In any case, I think the best thing to do next is to upload the new simple solution you just created so I can take a look.

Please make sure that you're using NorthwindIB database in order to debug this faster.


Posted By: BillG
Date Posted: 19-Feb-2014 at 9:52am
Ok I am getting closer to solving this. I got the sample application that you sent me to work. I then created a new solution for my application and moved the domain model over to it. I put the lines in the MainWindow_Loaded to access a table in my database and it worked. I then moved my app.config file to the new solution and it still worked. So i have proved the DomainModel is set up correctly and working fine and the configuration file is working fine.

so what else could it be? i put the same MainWindow_Loaded method in my application and it fails. So i has to be something with my Client project. I have no Web project as i got rid of that to make this simpler to figure out.


Posted By: DenisK
Date Posted: 20-Feb-2014 at 11:13am
Sounds like you're on the right track Bill. I'd try creating a fresh Client project and add modules until it breaks.


Posted By: BillG
Date Posted: 20-Feb-2014 at 1:52pm
ok i think i found the problem. In my Web application i need to have a reference to my domain model. From my client app i access the remote methods on the server app. I need a reference to the server app. but now i have a reference in my client app to the domain model and to the server app. In my server app i have a reference to the domain model. they both have the UnionData.cdsl, msl, and ssdl files in the domain model. So the app crashes thinking i have a multiple files.

How do i reference the domain model without having a reference to it?



Posted By: BillG
Date Posted: 21-Feb-2014 at 2:24am
forget it. Everything seems to be fine. The Precompiled views are finally working. For some reason, creating a new solution and moving everything over to it seemed to solve the problem. thank you Dennis for all your Dennis and for steering me in the right direction.




Print Page | Close Window