public class MyObj
{
[Key]
public int id {get; set;}
public string test1 {get; set;}
public string test2 {get; set;}
public int test3 {get; set;}
public int test4 {get; set;}
public int test5 {get; set;}
public int? test6 {get; set;}
public DateTime? test7 {get; set;}
public string test8 {get; set;}
public string test9 {get; set;}
public string test10 {get; set;}
public string test11 {get; set;}
public string test12 {get; set;}
public DateTime? test13 {get; set;}
public DateTime? test14 {get; set;}
public DateTime? test15 {get; set;}
public string test16 {get; set;}
public string tes17 {get; set;}
public int test18 {get; set;}
public DateTime? test19 {get; set;}
public bool test20 {get; set;}
[ForeignKey("test3")]
public virtual Child1 child1 { get; set; }
[ForeignKey("test4")]
public virtual Child2 child2 { get; set; }
[ForeignKey("test5")]
public virtual Child3 child3 { get; set; }
[ForeignKey("test18")]
public virtual Child4 child4 { get; set; }
public virtual ICollection<Child1> child5 { get; set; }
}
var myobj = unitwork.myobjRepository.get();
我只是想拉ID和測試1 test20,沒有child1,child2,child3,child4和child5。C#,實體框架,LINQ如何排除屬性
現在,我做的,
myobj.Select(x => new {
id = x.id,
test1 = x.test1
...
...
test20 = x.test20
}));
,但我不認爲這是正確的方式。請告訴我,
是什麼讓你覺得這是錯的? –
,因爲要排除5,需要選擇每個20 ...? –
沒有辦法從類型中「刪除」屬性。您可以將它們的值設置爲null或默認值,但不能刪除它們。 –