简体   繁体   中英

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"

it s happen after I

  • add new fields in database and update the model in entity entity-framework

  • after i put the dal (project contain entity entity-framework) in console project and rent this script

    Database.SetInitializer(new DropCreateDatabaseIfModelChanges());

to update the entity

but i have this error "The specified 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

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

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

and create the function inisde my repo member :

thank s to ADyson who help me for that

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

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