c# - Independent Association does not retrieve all rows when no foreign key constraint exists in database -
i using ef6.1 database first/objectcontext/pocos.
i have table called foo , table called foohistory. how model looks like:
due legacy reasons, foono primary key on foo, not on foohistory , foreign key constraint does not exist in database. however, logical foreign key, set 1 many independent association between foo , foohistory. principal/dependent property foono.
the following linq-to-entities query:
var qry = f in context.foo.include("history") f.foono.trim() == "someno" select f.history.count();
returns value of 6, whereas sql sent database returns 10 rows (which want).
i managed query give me full 10 rows creating foreign key constraint in database on foono , updating model. @ point ef referential constraint in association's properties changed name of database constraint. multiplicity changed, becoming 0...1 many.
however, i'd understand why first approach not work - why results different when in both cases query sent database same? going on internally?
Comments
Post a Comment