当我尝试这个时:
//IRepository.GetAll<CompanyPerson> returns an IQueriable
//ToObservableList() extension method converts to ObservableCollection
var tt =
(from s in container.Resolve<IRepository>().GetAll<Company>()
join t in container.Resolve<IRepository>().GetAll<Personels>().ToObservableList()
on s.ID equals t.CompanyID into k
from subset in k
select new { s, t = k }).ToList();
我得到这个例外:
Unable to create a constant value of type 'CompanyPerson'. Only primitive types ('such as Int32, String, and Guid') are supported in this context.
当我尝试这个时:
var tt =
(from s in container.Resolve<IRepository>().GetAll<Company>()
join t in container.Resolve<IRepository>().GetAll<Personels>()
on s.ID equals t.CompanyID into k
from subset in k
select new { s, t = k }).ToList();
或者当我尝试这个时:
(from s in container.Resolve<IRepository>().GetAll<Company>()
join t in container.Resolve<IRepository>().GetAll<Personels>()
on s.ID equals t.CompanyID into k
from subset in k
select new { s, t = new ObservableCollection<CompanyPerson>(k) }).ToList();
得到这个:
Only parameterless constructors and initializers are supported in LINQ to Entities.
ToObservableList() 扩展:
public static ObservableCollection<T> ToObservableList<T>(this IEnumerable<T> data)
{
ObservableCollection<T> dataToReturn = new ObservableCollection<T>();
foreach (T t in data)
dataToReturn.Add(t);
return dataToReturn;
}
没有例外。
有什么建议吗?
谢谢。