c# - Adding a conditional join in entity framework 4.0 -



c# - Adding a conditional join in entity framework 4.0 -

i trying inner bring together in ef4, if status met. have function like:

list<articles> search(int? postsiteid) { var myquery = articles in context.articles articles.isdeleted = 0; if(postsiteid != null) { // add together inner bring together on posts table , check posts.siteid = postsiteid --- } }

i unsure how add together bring together , status within of if statement, outside of main query. ive found nil searching few hours.

im not sure if bring together neccessary though. if add together condition: query = query.where(article => article.posts.any(p => p.siteid == postsiteid.value)), know bring together there? or subselect?

the easiest thing try , @ generated sql... suspect utilize nested subselect, query optimizer work out join-like construct, i'd expect.

you can bring together yourself, making sure select original value again... if you're interested in finding out wehether of posts have given site id, "any" alternative cleaner. normal bring together end returning duplicate articles if there multiple matching posts. utilize distinct, seems little pointless.

c# linq entity-framework entity-framework-4 linq-to-entities

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -