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 (Organization mattresses in the form of IDC guide, as coded) categories = lists. Categories in categories such as category categories = x in categories where x.codId = codId x and sub end class Select

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

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -