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

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -