I use this code for select two field
public ViewModelList(CRMEntities crm)
{
var cus = (from c in crm.Customer
select new
{ c.Name, c.Family });
AllCustomer = new ObservableCollection<Custom>(cus.ToList());
}
public ObservableCollection<Custom> AllCustomer
{
get;
set;
}
}
public class Custom
{
public string Name{get;set;}
public string Family { get; set; }
}
, but gives the following error
cannot convert from ‘System.Collections.Generic.List’ to ‘System.Collections.Generic.List’
In your ObservableCollection you are specifying that the element is of type Custom.
When you perform the select you are creating an anonymous type. Using new { … } will create an anonymous type.
What you probably want to do is