c# - Linq to Entities - Projections against Query Syntax vs Method Syntax -
since linq query expression translated "under covers" call same methods corresponding method query call (at least think so), expect these 2 queries return same type. reason though this:
var result = in db.invoices select new { i.invoicenum }; sets result iqueryable<'a> each member having invoicenum property, while this
iqueryable<string> result2 = db.invoices.select(i => i.invoicenum); is smart enough return iqueryable<string> (obviously, since compiles)
clearly 1 of assumptions wrong, , hoping expert me understand bit better.
(this ef4, same happens linq-to-objects, , i'm guessing same happen l2s)
when write new { } creating anonymous type
try
var result = in db.invoices select i.invoicenum; and see returns type expect.
Comments
Post a Comment