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.

Entity Framework: reload all child entities from query based on child entity attributes -


is there way elegantly load child entities of ef entity if entity instance loaded result of query on child entity attributes? here simple example of i'm asking:

first, simple data tables:

create table invoices (     invoiceid int identity(1000,1) not null,     customer nvarchar(50) not null,     invoicedate datetime not null,     constraint pk_invoices primary key (invoiceid) )  create table invoiceitems (     invoiceitemid int identity(1,10) not null,     invoicefk int not null,     purchaseditem varchar(24) null,     quantity decimal(10,2) null,     itemprice money null,     constraint pk_invoiceitems primary key (invoiceitemid),     constraint fk_invoiceitems_invoice foreign key (invoicefk)         references invoices (invoiceid) ) 

now, want query invoice table based on matching invoice item, show items each selected invoice regardless of whether matches criteria:

var qryorders = ordr in ctx.invoiceitems                 .include("invoice")                 ordr.purchaseditem == "buggy whips"                 select ordr;  foreach (var ordritm in qryorders) {     console.writeline("order " + ordritm.invoice.invoiceid + " contains buggy whips");     console.writeline("full contents of order:");      foreach (var itm in ordritm.invoice.invoiceitems)     {         //this show buggy whip item         console.writeline(itm.purchaseditem);     } } 

what want show order items in each order contains "buggy whips", including items not buggy whips. if writing in sql, use where invoiceid in () clause subquery. question is: can entity framework make happen in elegant way? i've come hacks work, nothing feels right.

pretty confusing question - i'll attempt answer statement:

what want show order items in each order contains "buggy whips", including items not buggy whips.

i think need flip invoiceitems/invoice around:

var query = ctx.invoices.include("invoiceitems")                .where(x => x.invoiceitems.any(y => y.purchaseditem == "buggy whips"))                .select(x => x.invoices); 

that query return collection of invoices, have @ least one purchased item of "buggy whips".

if want return collection of invoices all of purchased items "buggy whips", replace .any .all.

not sure if after.

a part confuses me this:

if writing in sql, use invoiceid in () clause subquery

invoiceid on invoices table - item name (purchaseditem) on invoiceitems table - how work?

perhaps if wrote example sql query convert linq-entities.


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 -