Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - linq to sql optimized a group with multiple joins -


i need generating more efficient linq query:

table: positions -positionid -name  table: person -personid -name, etc...  table: personposition -personid -positionid 

i need result set groups people assigned each position:

positionid  person 1           john             bob             frank  2           bill             tom             frank, etc... 

my first thought linq query:

from perspos in personpositions join pers in persons            on perspos.personid equals pers.personid  group pers perspos.positionid groups select new {groups.key, groups} 

which works great, produces following sql:

select [t0].[positionid] [key] [personposition] [t0] inner join [person] [t1] on [t0].[personid] = [t1].[personid] group [t0].[positionid] go  -- region parameters declare @x1 int = 3 -- endregion select [t1].[personid], [t1].[userid], [t1].[firstname], [t1].[lastname], [t1].[email], [t1].[phone], [t1].[mobile], [t1].[comment], [t1].[permissions] [personposition] [t0] inner join [person] [t1] on [t0].[personid] = [t1].[personid] @x1 = [t0].[positionid] go  -- region parameters declare @x1 int = 4 -- endregion select [t1].[personid], [t1].[userid], [t1].[firstname], [t1].[lastname], [t1].[email], [t1].[phone], [t1].[mobile], [t1].[comment], [t1].[permissions] [personposition] [t0] inner join [person] [t1] on [t0].[personid] = [t1].[personid] @x1 = [t0].[positionid] go  -- region parameters declare @x1 int = 5 -- endregion select [t1].[personid], [t1].[userid], [t1].[firstname], [t1].[lastname], [t1].[email], [t1].[phone], [t1].[mobile], [t1].[comment], [t1].[permissions] [personposition] [t0] inner join [person] [t1] on [t0].[personid] = [t1].[personid] @x1 = [t0].[positionid] go  on , on... 

is there better linq query translates more efficient sql statement?

you should have relationship defined in database, , on dbml.

avoid doing joins when don't have to; tedious. let linq-to-sql you. should work:

var data = context.personpositions     .select(pos => new { pos.positionid, pos.person }); return data.groupby(pos => pos.positionid); 

or

return context.positions.select(pos =>      new { pos, pos.personpositions.select(pp => pp.person).tolist() }).tolist(); 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -