c# - Create a query using LINQ to entities with 1:N relation -


i know it's not unusual make such kind of queries think lost seek help. have tables relation 1:n , make more clear i'll post print screen management studio :

table relation

i working on asp.net mvc 3 project , need make view documents shown (and filter , stuff, think irrelevant case). need data table documents , 1 specific record each document documentfields table. record record holding name of document , it's uniqueness documentid == docmuents.id, documentfields.rowno == 1 , documentsfields.columnno == 2. unique record every document , need fieldvalue record holds name of document.

i not sure how build query (maybe using join) , make view typed passing model of type documents i'm not sure if it's possible, think depending on way query build determine type of model view.

i believe want this:

var results =      d in dbcontext.documents     join df in dbcontext.documentfields      on new { d.id, rowno = 1, columnno = 2 } equals         new { id = df.documentid, df.rowno, df.columnno }     select new      {         document = d,         documentname = df.fieldvalue     }; 

of course if set navigation properties, can this:

var results =      d in dbcontext.documents     let df = d.documentfields.first(x => x.rowno == 1 && x.columnno == 2)     select new      {         document = d,         documentname = df.fieldvalue     }; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -