asp.net mvc - Linq select from list -
I can not understand this, I am not new to the MVC model, but maybe my brain is just tired. Public category categories as a list of public sector (cihCategoryOrgDef) cihCategoryOrgDef public property as the public property category, this name as the string public sub
See model
CategoriesController
When I run it, give me the Class = from x .... line
gets an object cast exception 'WhereSelectLi To type 'library.cihCateg oryOrgDef, Library.cihCategoryOrgDef]', type 'library.cihCategoryOrgDef'.
I use a single
category I'm trying to get That's why I might be an editing page for that specific category. Am I doing all this wrong?
Since class is for the alone category , You need to make sure that your LINQ returns a single result if you are sure that the query returns only one value, then use SingleOrDefault :
Category = (Select from x to x.codId = codId in x) .SingleOrDefault () If your query can return more than one result and you only want to get the first result , Then use FirstOrDefault :
category = (In the categories in x where x.codId = codId select x). FirstOrDefault ()
Comments
Post a Comment