0
選擇的參數我有一個實體:返回從LINQ對象
public class Branch
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int BranchID { get; set; }
public string Name { get; set; }
public string Address1 { get; set; }
public string Address2 { get; set; }
public string Postcode { get; set; }
public string City { get; set; }
public string State { get; set; }
public string Country { get; set; }
}
我有一個apicontroller函數返回的樹枝對象:
IEnumerable<Branch> branches = null;
branches = repository.Branches.Where(b => b.LastModified > modifiedSince).AsEnumerable();
return branches;
我怎麼只能返回BranchID
和Name
?
我已經試過這樣:
IEnumerable<Branch> branches = null;
branches = repository.Branches
.Where(b => b.LastModified > modifiedSince)
.Select(b => new Branch {BranchID = b.BranchID, Name = b.Name })
.AsEnumerable();
return branches;
您試過了,發生了什麼問題? – nawfal