Author |
Share Topic Topic Search Topic Options
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
Topic: dbConttext and Precompiled Views 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
|
|
DenisK
IdeaBlade
Joined: 25-Aug-2010
Posts: 715
|
Post Options
Quote Reply
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.
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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?
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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.
|
|
DenisK
IdeaBlade
Joined: 25-Aug-2010
Posts: 715
|
Post Options
Quote Reply
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.
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
Posted: 14-Feb-2014 at 5:57pm |
no it is a WPF app. My DomainModel project is linked on the client.
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
Posted: 14-Feb-2014 at 6:06pm |
do i also have put the views.cs in the client project?
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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
|
|
DenisK
IdeaBlade
Joined: 25-Aug-2010
Posts: 715
|
Post Options
Quote Reply
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
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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.
|
|
DenisK
IdeaBlade
Joined: 25-Aug-2010
Posts: 715
|
Post Options
Quote Reply
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.
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
Posted: 17-Feb-2014 at 4:20pm |
its redirecting me to a login page.
|
|
JoshO
IdeaBlade
Joined: 09-May-2007
Location: United States
Posts: 86
|
Post Options
Quote Reply
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.
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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.
|
|
BillG
DevForce MVP
Joined: 05-Dec-2007
Location: Monroe, MI
Posts: 233
|
Post Options
Quote Reply
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); } }
|
|