none
EntityFramework metadata resources

    Question

  • Hi All,

    I have problem with set up correct metadata res in app.config.

    I am creating WCF server application which provide access to database.

    My ssdl, msl and csdl files are in Assembly/EntityModel/...

    When i hosted this WCF server in console app, my connection string looks like:

    <add name="xpdir2ModelContainer" connectionString="metadata=.\EntityModel\xpdir2Model.csdl|.\EntityModel\xpdir2Model.ssdl|.\EntityModel\xpdir2Model.msl;provider=Npgsql;provider connection string=&quot;Port=5432;Encoding=WIN1250;Server=localhost;Database=xpdir2_mvc;UserId=postgres;Password=postgres&quot;" providerName="System.Data.EntityClient"/>

    and everythings works correctly. After i change hosting from console app to windows service, it stops working. I know, when i install service, its current directory is something like Windows/Wow64/...

    So i was trying to set metadata files as embedded resource. I use:

     <add name="xpdir2ModelContainer" connectionString="metadata=res://*/EntityModel.xpdir2Model.csdl|res://*/EntityModel.xpdir2Model.ssdl|res://*/EntityModel.xpdir2Model.msl;provider=Npgsql;provider connection string=&quot;Port=5432;Encoding=WIN1250;Server=localhost;Database=xpdir2_mvc;UserId=postgres;Password=postgres&quot;" providerName="System.Data.EntityClient"/>

    But this doesn't works. It throws exception:

    {System.Data.MappingException: Schema specified is not valid. Errors: 
    EntityModel.xpdir2Model.msl(5,4) : error 2062: No mapping specified for instances of the       EntitySet and AssociationSet in the EntityContainer xpdir2ModelContainer.

    When is use absolute paths to metadata files, everything works. Does anybody knows, what is the problem?

    Thanks. Regards


    • Edited by dEVIANT22 Monday, January 13, 2014 7:49 AM update
    Monday, January 13, 2014 7:49 AM

Answers

  • Thanks. 

    Finally i found solution. I am changing Environment.CurrentDirectory to directory, from which was service installed.

    I used:      Environment.CurrentDirectory = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;

    Regards

    Saturday, January 18, 2014 10:44 AM

All replies

  • Hello,

    >>When is use absolute paths to metadata files, everything works. Does anybody knows, what is the problem?

    Does the three files under a dll file? If it is, please have a try to add dll file name like below:

    res://Simple Mvc.Data.dll/Model.csdls

    Craig Stuntz has written an extensive blog post on troubleshooting this exact error message:

    http://blogs.teamb.com/craigstuntz/2010/08/13/38628/

    >>for instances of the EntitySet and AssociationSet in the EntityContainer xpdir2ModelContainer.

    As far as I know, this error is caused by that there are objects are not mapped correct in the model, please check if there is not mapped field.

    If I misunderstand, please let me know.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, January 14, 2014 8:52 AM
  • Thanks. 

    Finally i found solution. I am changing Environment.CurrentDirectory to directory, from which was service installed.

    I used:      Environment.CurrentDirectory = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;

    Regards

    Saturday, January 18, 2014 10:44 AM