简体   繁体   English

更新数据库后出现实体框架错误

[英]entity-framework error after update database

I have this error with entity freamwork 我在实体框架上遇到此错误

"The specified LINQ expression contains references to queries that are associated with different context" “指定的LINQ表达式包含对与不同上下文关联的查询的引用”

it s happen after I 它发生在我之后

  • add new fields in database and update the model in entity entity-framework 在数据库中添加新字段并在实体entity-framework中更新模型

  • after i put the dal (project contain entity entity-framework) in console project and rent this script 在我将dal(项目包含实体entity-framework)放入控制台项目并租用此脚本之后

    Database.SetInitializer(new DropCreateDatabaseIfModelChanges()); Database.SetInitializer(new DropCreateDatabaseIfModelChanges());

to update the entity 更新实体

but i have this error "The specified LINQ ..." 但是我有这个错误“指定的LINQ ...”

I checked in internet they said i have to update the .tt files or .edmx files but didin t found any tt files or edmx file in my dal project 我检查了互联网,他们说我必须更新.tt文件或.edmx文件,但没有在我的dal项目中找到任何tt文件或edmx文件

can you plz help me thank you 你能帮我谢谢你吗

I Found where are my error 我发现我的错误在哪里

the is tried to query two repository 试图查询两个存储库

didn't know each repository has his own db context my error was that : 不知道每个存储库都有自己的数据库上下文,我的错误是:

from football in  repoFootabll.Query().Where (x => x.id = 12)
From members in repoMember.Query().where(x=> x.FootaballId = football.id)
select (repo2)

To fix that i just add dbset of football in Member repository 要解决此问题,我只需在会员存储库中添加football dbset

class repoMember 
{
    dbSet<football> foot
    dbSet<member> memeber
 ...
}

and create the function inisde my repo member : 并创建函数inisde我的回购成员:

thank s to ADyson who help me for that 感谢ADyson的帮助,他为此提供了帮助

getmemebers()
{
     from football in  foot.Where (x => x.id = 12)
    From members in memeber.where(x=> x.FootaballId = football.id)
    select (members)
}

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

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