如何在实体框架中显示表的某些特定列,而不是整个表。
using (DataEntities cxt = new DataEntities())
{
notes note = cxt.notes.Where(no => no.id == accID).SingleOrDefault();
return notes;
}
发布于 2011-11-25 09:17:47
为此,我建议您使用ViewModel,如下所示:
notes note = cxt.notes.SingleOrDefault(no => no.id == accID);
var model = new YourViewModel // Your viewModel class
{
ID = note.ID,
PropertyOne = note.PropertyOne, // your ViewModel Property
PropertyTwo = note.PropertyTwo
};
发布于 2011-12-19 12:16:47
您可以使用QueryView来实现这一点。这意味着直接在XML中编辑模型,因为没有设计器对此的支持,但您将获得一个独立的实体,其字段比原始实体少。
的优势:
Disadvantages:
的读/写功能
https://stackoverflow.com/questions/8266546
复制