c# - Linq Foreign Key Select -


i have 2 tables 1 (articles) many (details) relationship. details may not contain data particular article entry.

articles: id, title, numb (pk), name

details: id (pk), person, numb (fk), name

in entity framework, there appropriate navigation properties , shows correct one:many relationship.

what want articles match end user's query (by 'name') all, if any, data details table (id, person, numb, name).

what i'm stuck on right can query articles fine (var article = db.articles.where(b => b.name.equals(name));), while result include hashset details.numb on each row of articles, there no data in hashset. there appropriate corresponding entries in database article.numb => details.numb.

actually there 2 ways achieve this.

  1. enable lazy loading.
  2. call include method other answers says.

using lazy loading see msdn article more detail.

    db.contextoptions.lazyloadingenabled = true; 

using include method

    var article = db.db.articles.include("details").where(b => b.name.equals(name))).firstordefault(); 

Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -