c# - Cannot serialise entites to viewmodel type via constructor -


i having problem only parameterless constructors , initializers supported in linq entities., , not sure how resolve this, can potentially remove constructor , initialise these manually code there wondering if done.

var entries = db.devices.select(device => new devicedetailsmodel(device)).tolist(); devices.addrange(entries); 

and here constructor class

 public devicedetailsmodel(device device)     {         deviceid = device.deviceid;         ipaddress = device.ipaddress;         alias = device.alias;         devicename = device.devicename;     } 

you using linq entities not linq objects. that`s difference. linq entities translates linq query sql query , has no idea how translate constructor. use initializer instead - linq entity can handle that:

  var entries = db.devices.select(x => new devicedetailsmodel {     deviceid = x.deviceid;     ipaddress = x.ipaddress;     alias = x.alias;     devicename = x.devicename; }).tolist(); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -