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:
- use var instead of
list<>
- 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
Post a Comment