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

windows - Why does Vista not allow creation of shortcuts to "Programs" on a NonAdmin account? Not supposed to install apps from NonAdmin account? -

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

unit testing - How to mock PreferenceManager in Android? -