Linq List<> problem -


northwinddatacontext db = new northwinddatacontext(); list<category> lresult = (db.categories          .select(p => new { p.categoryid, p.categoryname, p.description })).tolist(); 

in above query don't want use var instead of var want use list<> show me error .why error occur ,how correct query.

your query selecting anonymous type, not instances of category. that's why you're going need either:

  1. use var instead of list<>
  2. create named type instead of using anonymous type in query.

anonymous types unspeakable - there no type name can refer them in code. exist make easier create projections in linq queries without having write explicit type each result.

in case, there's no real downside using var. that's why exists. allows refer anonymous types without having give them name (since can't). use:

var lresult = (db.categories.select( ... // query... 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -