entity framework - filtering query with nullable join keys
I have a query based on the following T SQL:
select t1.field1
t2.field1,
t2.field2,
t3.field1,
t3.field2
from t1 left outer join t2 on t1.t2key = t2.id
left outer join t3 on t1.t3key = t3.id
In 开发者_开发技巧Linq to Entities the query takes the form
var query = db.context.t1.include(“t2”).include(“t3”);
The table t1 has an unusual structure in that fields t2key and t3key are nullable. The nullable fields are preventing me from filtering by any of the t2 or t3 fields.
The only way out I can see so far is to return the results as a database view before I perform the filtering. Or is there another approach I should be taking here?
For what it's worth I ended up using Linq in the end. If anyone else is in the same boat this is the syntax that got around the nullable issue:
query = query.Where(x => x.t1field != null ? x.t1field.t3field.Contains(model.propvalue) : false).Select(x => x);
精彩评论