EF6 全选并设置一个字段
有没有一种方法可以选择集合中的所有属性并设置一个属性,而无需详细地重新映射整个属性列表?
return =
_input.Where(
w => w.MaterialNumber.Contains("foo")
).Select(s => new Material.list() { ID = s.ID, MaterialNumber = s.MaterialNumber, orColor = "#303030" }).ToList()
);
寻找更简单的东西。
return =
_input.Where(
w => w.MaterialNumber.Contains("foo")
).Select(s => new Material.list() {s, new orColor = "#303030" }).ToList()
);
Is there a way to select all the properties in a collection and set one without verbosly remapping the entire property list?
return =
_input.Where(
w => w.MaterialNumber.Contains("foo")
).Select(s => new Material.list() { ID = s.ID, MaterialNumber = s.MaterialNumber, orColor = "#303030" }).ToList()
);
Looking for something simpler.
return =
_input.Where(
w => w.MaterialNumber.Contains("foo")
).Select(s => new Material.list() {s, new orColor = "#303030" }).ToList()
);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提到了 EF 6,但您实际上并未在问题中使用它。您还提到了映射,但您确定是否需要它?如果其他代码可以使用相同的实例而不需要重新映射,只需使用下面列出的任何方法来设置原始对象的属性
You mentioned EF 6 but you don't actually use it in the question. Also you mentioned mapping, but are you sure if it is required? If it is possible for other code to use same instance without remapping, just use any approach listed below to set property of the original object