问题
I have used the Entity framework to populate a checked list box. I want to get the names of the checked items as a string collection so that they can then be used as a filter for another LINQ query.
I populate the list box like this...
_eventTypesCheckedList.DataSource = this._dataContext.tblEventTypes.OrderBy(ev => ev.EventTypeName);
_eventTypesCheckedList.DisplayMember = "EventTypeName";
This is how I'm failing to get the string collection...
var types = from eType in ((_eventTypesCheckedList.CheckedItems) as IEnumerable< tblEventType > )
select new string( eType.EventTypeName.ToCharArray() );
Any help would be great.
回答1:
Cast your CheckItems
collection using .Cast<Type>()
extension method:
_eventTypesCheckedList.CheckedItems.Cast<tblEventType>()
来源:https://stackoverflow.com/questions/10626107/create-a-string-collection-from-checkedlistbox-checkeditems-using-linq