Hi,
I have a table that I need to extract data from, and wish to discard one of the two columns that the data comes from. In my DB, I have "ObjectID (PK)" and "ObjectName".
I wish to use this data to populate a SelectList in an ASP.NET MVC project, and so have an IQueryable object in my code which looks as follows:
public IQueryable<objectRef> FindSomeObject()
{
return from myObj in db.TableName
orderby myObj.colName
select myObj;
}
If I attempt to change the last line to pull only a single column worth of data, such as:
select new { myObject.colName };
I get a warning that I am attempting to implicitly convert an anonymous type to my current type.
The annoyance is that this query gets used in ViewData[""]
to set a SelectList
, which displays the drop down fine, but writes the PK value to the new table instead of the text.
I'm assuming that I know so little about this that I cannot even ask Google the right question, as hours of RTFM have revealed nothing useful. Any help would be appreciated.