鑑於這種表:LinqToSQL - 閱讀對象,只有某些屬性
Foo
P1
P2
P3
我怎麼能只用P1讀富?我的執行:
public Foo GetFooWithP1(int id)
{
using (DbDataContext db = new DbDataContext())
{
var query =
from f in db.Foos
where f.Id == id
select new
{
P1 = m.P1
};
var data = query.SingleOrDefault();
return new Foo
{
P1 = data.P1
};
}
}
有沒有其他的選擇?
謝謝,馬克,爲你提示!現在讓我把事情複雜化:-) http://stackoverflow.com/questions/959417/linqtosql-read-objects-hierarchy-with-only-certain-properties – alex2k8 2009-06-06 10:19:15