Table value parameter for IQueryable connection
Therefore, for various reasons, we need to send a large list of identifiers in an EF6 request.
queryable.Where(x => list.Contains(x.Id));
not perfect as it will create a huge list.
So I thought, is it possible for some home show to pass a table value parameter with ids and get an IQueryable that I can join?
something like (Pseudocode)
var queryable = TableValueToIQueryable<MyTableValueType>(ids);
context.Set<MyEntity>().Join(queryable, x => x.Id, x.Value, (entity, id) => entity);
Is it possible somehow?
update: I was able to use EntityFramework.CodeFirstStoreFunctions
to execute sql function and map data against IQueryable<MyEntity>
. it uses CreateQuery
and ObjectParameters
, is there any way to use table value parameters with ObjectParamters?
update2: Set (). SqlQuery (...) will work with table value parameters, but the resulting DbSqlQuery will not be merged in SQL with IQuery, so the result will be two joins, and the join is done in memory
var idResult = Set<IdFilter>().SqlQuery("select * from GetIdFilter(@ids)", parameter);
var companies = idResult.Join(Set<tblCompany>(), x => x.Id, y => y.CompanyID, (filter, company) => company).ToList();
update3: ExecuteStoreQuery
((IObjectContextAdapter)ctx).ObjectContext.ExecuteStoreQuery<InvoicePoolingContext.IdFilter>("select * from dbo.GetIdFilter(@ids)", parameter)
.Join(ctx.Set<tblCompany>(), x => x.Id, y => y.CompanyID, (filter, company) => company).ToList();
Gives an error:
There is already an open DataReader associated with this Command, which must be closed first.
source to share
No one has answered this question yet
Check out similar questions: