简体   繁体   中英

EntityFramework Schema specified is not valid

I know this question was already asked but it seams that my case might be slightly different. I tried the "run custom tool" but here's where the strange thing happens: Because i'm having 2 related databases (so 2 related models). If i'm running the custom tool on one model it screws up the other and vice-versa(incomplete .cs files, missing, etc.). Does anyone have any ideea where i'm going wrong?

EDIT:

the complete error:

An exception of type 'System.Data.Entity.Core.MetadataException' occurred in EntityFramework.dll but was not handled in user code

Additional information: Schema specified is not valid. Errors:

The relationship 'ProductionMasterDataEntityModel.FK_ProductGroup_CostPeriods' was not loaded because the type 'ProductionMasterDataEntityModel.ProductGroup' is not available.

The following information may be useful in resolving the previous error:

The required property 'CstAveOrderQty' does not exist on the type 'SISCOM.Persistance.Models.ProductGroup'.

The custom tool is: TextTemplatingFileGenerator

I'm not sure if it has anything to do with the asp.net framework but it is an asp.net project so i thought it's worth mentioning.

in my case, this Issue came after I update .edmx file. Remove all the tables on it and re-update it.right click on .tt file(Eg. Entity.tt) file->Run custom tools. then my issue solved.

Drop the model from edmx and add it again should sort it out. Note this cannot be reverted unless using source control tools.

It seams that i had 2 problems contributing to that error.. First, there were some stored procedures and views, after i got that out of the way (deleted my models, created them again and i've unchecked the option to include the stored procedures and i only added the tables to the model, no views and no stored procedures) i could access some data but not all of it.. The second problem was that i forgot to add a connection to the dependent database.

So the methods in my repository look like this:

public myType GetSomething()
{
 var db = new model();
 var dependencyDb = new dependencyModel();
 //do whatever needs to be done with the data before presenting it
 return something;
}

PS.. i didn't had to explicitly take it to the needed table, after i added the connection it found all that it needed by itself.

Hope this helps anyone having this problem.

I solve this case like below.

Entity in class lib project and i was try to consume in other project. So in that project i have add reference "EntityFramework.SqlServer.dll" in new project.

Schema specified is not valid. Errors: MyModel.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM