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
Post a Comment