简体   繁体   English

指定的实体框架架构无效

[英]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).我尝试了“运行自定义工具”,但这里发生了奇怪的事情:因为我有 2 个相关的数据库(所以有 2 个相关的模型)。 If i'm running the custom tool on one model it screws up the other and vice-versa(incomplete .cs files, missing, etc.).如果我在一个模型上运行自定义工具,它会搞砸另一个模型,反之亦然(不完整的 .cs 文件、丢失等)。 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 EntityFramework.dll 中发生类型为“System.Data.Entity.Core.MetadataException”的异常,但未在用户代码中处理

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.关系“ProductionMasterDataEntityModel.FK_ProductGroup_CostPeriods”未加载,因为类型“ProductionMasterDataEntityModel.ProductGroup”不可用。

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'.类型“SISCOM.Persistance.Models.ProductGroup”上不存在所需的属性“CstAveOrderQty”。

The custom tool is: TextTemplatingFileGenerator自定义工具是: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.我不确定它是否与 asp.net 框架有关,但它是一个 asp.net 项目,所以我认为值得一提。

in my case, this Issue came after I update .edmx file. 就我而言,此问题是在我更新.edmx文件之后出现的。 Remove all the tables on it and re-update it.right click on .tt file(Eg. Entity.tt) file->Run custom tools. 删除所有表并重新更新。右键单击.tt文件(例如Entity.tt)文件->运行自定义工具。 then my issue solved. 然后我的问题解决了。

Drop the model from edmx and add it again should sort it out. 将模型从edmx中删除,然后再次添加,应进行分类。 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. PS ..添加连接后,它无需自行将其​​显式添加到所需的表中,因此它可以自行找到所需的所有内容。

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. 类lib项目中的实体,而我尝试在其他项目中使用。 So in that project i have add reference "EntityFramework.SqlServer.dll" in new project. 因此,在该项目中,我在新项目中添加了引用“ EntityFramework.SqlServer.dll”

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'.错误:MyModel.ssdl(2,2):错误 0152:未找到具有不变名称“System.Data.SqlClient”的 ADO.NET 提供程序的实体框架提供程序。 Make sure the provider is registered in the 'entityFramework' section of the application config file.确保提供程序已在应用程序配置文件的“entityFramework”部分注册。 See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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