entity framework - LINQ to Entities does not recognize the method 'Int32 Min(Int32, Int32)'? -
im getting error when execute following code, ideas how fix it?
linq entities not recognize method 'int32 min(int32, int32)' method, , method cannot translated store expression.
result = items.tolist() .select(b => new batchtoworkonmodel() { batchid = b.batch.id, summarynotes = b.batch.notes, rowversion = b.batch.rowversion, items = items .select(i => new itemtoworkonmodel() { suppliertitle = i.title, itemid = i.id, batchid = i.batchid ?? 0, itemdate = i.pubdate, // kb - issue 276 - return correct outlet name each item outlet = i.items_supplierfields != null ? i.items_supplierfields.suppliermediachannel != null ? i.items_supplierfields.suppliermediachannel.name : null : null, status = ((short)itemstatus.complete == i.statusid ? "done" : "not done"), numberinbatch = i.numinbatch, text = string.isnullorempty(i.body) ? "" : i.body.substring(0, math.min(i.body.length, 50)) + (i.body.length < 50 ? "" : "..."), isrelevant = i.isrelevant == 1, previouslycompleted = i.previouslycompleted > 0 ? true : false }).tolist() }) .firstordefault();
it seems math.min not implemented ef query provider. should able fix applying asenumerable
on items collection expression using linq objects instead;
items = items.asenumerable().select(i => new itemtoworkonmodel()...
if add where
condition item selection (seems little strange take items in whole table), you'll want add before asenumerable() allow ef filtering in database.
also, want first result query, you're fetching all of them using tolist()
before cutting list down single item. may want remove tolist()
ef/the underlying database can return single result;
result = items.select(b => new batchtoworkonmodel()...
Comments
Post a Comment