Note that there are some explanatory texts on larger screens.

plurals
  1. POFaking Entity Framework and attempting to LINQ query it gives error
    primarykey
    data
    text
    <p>We have been trying to figure out how to fake the DbContext. So we followed the example here</p> <p><a href="http://romiller.com/2012/02/14/testing-with-a-fake-dbcontext/" rel="nofollow">http://romiller.com/2012/02/14/testing-with-a-fake-dbcontext/</a></p> <p>And the code (one for the abstraction layer over EF (error below) and one directly using EF (works fine)...</p> <p>All I can figure is maybe this has to do with the abstracted objects over top of the pre generated EF objects do not have a concept of relationship between tables/entities?? any idea?</p> <p>We have just been trying to find some way to have a common path for our fakes and the real code.. maybe the easy answer is to stop doing it this way and just mock calls to the repository and then unit tests after that point ? </p> <pre><code> CongressContext context = new CongressContext(); var repo = new CongressRepository(context); // IEnumerable&lt;tMember&gt; members = repo.Get100MembersDirectEF(); IEnumerable&lt;tMember&gt; members = repo.Get100Members(); </code></pre> <p>..............</p> <pre><code> public class CongressRepository : ICongressRepository { ICongressContext db; CongressDb_DevEntities realDb = new CongressDb_DevEntities(); public CongressRepository() { this.db = new CongressContext(); } public CongressRepository(ICongressContext context) { this.db = context; } public List&lt;tMember&gt; Get100Members() { var members = db.Members.Where(x =&gt; x.MembersID &lt; 100).ToList(); return members; } public List&lt;tMember&gt; Get100MembersDirectEF() { realDb.Configuration.LazyLoadingEnabled = false; var members = realDb.tMembers.Where(x =&gt; x.MembersID &lt; 100).ToList(); return members; } {"One or more validation errors were detected during model generation:\r\n\r\nCongress.Data.tEducationType: : EntityType 'tEducationType' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tCongress: : EntityType 'tCongress' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tCongressMemPositionReason: : EntityType 'tCongressMemPositionReason' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tReasonType: : EntityType 'tReasonType' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tDistrict: : EntityType 'tDistrict' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tParty: : EntityType 'tParty' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tPosition: : EntityType 'tPosition' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tChamber: : EntityType 'tChamber' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tState: : EntityType 'tState' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tMemMilitary: : EntityType 'tMemMilitary' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tMemOccupation: : EntityType 'tMemOccupation' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tOccupationType: : EntityType 'tOccupationType' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tInterestGroup: : EntityType 'tInterestGroup' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tRaceType: : EntityType 'tRaceType' has no key defined. Define the key for this EntityType.\r\nCongress.Data.tReligion: : EntityType 'tReligion' has no key defined. Define the key for this EntityType.\r\ntEducationTypes: EntityType: EntitySet 'tEducationTypes' is based on type 'tEducationType' that has no keys defined.\r\ntCongresses: EntityType: EntitySet 'tCongresses' is based on type 'tCongress' that has no keys defined.\r\ntCongressMemPositionReasons: EntityType: EntitySet 'tCongressMemPositionReasons' is based on type 'tCongressMemPositionReason' that has no keys defined.\r\ntReasonTypes: EntityType: EntitySet 'tReasonTypes' is based on type 'tReasonType' that has no keys defined.\r\ntDistricts: EntityType: EntitySet 'tDistricts' is based on type 'tDistrict' that has no keys defined.\r\ntParties: EntityType: EntitySet 'tParties' is based on type 'tParty' that has no keys defined.\r\ntPositions: EntityType: EntitySet 'tPositions' is based on type 'tPosition' that has no keys defined.\r\ntChambers: EntityType: EntitySet 'tChambers' is based on type 'tChamber' that has no keys defined.\r\ntStates: EntityType: EntitySet 'tStates' is based on type 'tState' that has no keys defined.\r\ntMemMilitaries: EntityType: EntitySet 'tMemMilitaries' is based on type 'tMemMilitary' that has no keys defined.\r\ntMemOccupations: EntityType: EntitySet 'tMemOccupations' is based on type 'tMemOccupation' that has no keys defined.\r\ntOccupationTypes: EntityType: EntitySet 'tOccupationTypes' is based on type 'tOccupationType' that has no keys defined.\r\ntInterestGroups: EntityType: EntitySet 'tInterestGroups' is based on type 'tInterestGroup' that has no keys defined.\r\ntRaceTypes: EntityType: EntitySet 'tRaceTypes' is based on type 'tRaceType' that has no keys defined.\r\ntReligions: EntityType: EntitySet 'tReligions' is based on type 'tReligion' that has no keys defined.\r\n"} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload