odata - Populating IEnumerable<MyType> using Linq gives error "The specified type member is not supported in LINQ to Entities." -
i have model in fields directly mapped database table , expose through odata (v4). created 1 unmapped property ienumerable , map runtime in webapiconfig. model looks this
public class myclass { public int id {get;set;} public string name {get;set;} [notmapped] [foreignkey("mytype")] public virtual ienumerable<mytype> mycollection { { return context.mycollection.asqueryable(); } set { ;} } }
now when run , try results url http://localhost/odataservice/myclass(1)?$expand=mycollection, gives me error saying "message": "the specified type member 'test' not supported in linq entities. initializers, entity members, , entity navigation properties supported.
can point out how populate ienumerable runtime using linq?
thanks.
the error saying type doesn't map db entity. guess mytype
c# type no db equivalent (seems said in question). ienumerable<mytype>
fine when use it, needs in context of linq objects not linq entities or linq sql. if want populate ienumerable<mytype>
@ runtime correct way of doing this;
ienumerable<mytype> mytypes = somecollectionfrommydb.select(x => new mytype { fieldonmytype=x.columna, otherfield=x.columnb });
basically, should use select
on linq entities collection project entities instances of mytype
when need them.
Comments
Post a Comment