1
我在EF6中遇到问题。当我执行查询Select
时,它返回值。但是当我添加Select
时,它返回null。实体框架6 - 嵌套查询中的空值与选择
的代码是在这里:
的(W)不为null这里...
var list = db.X.Include("Y").Include("Z.W")
.OrderBy(c => c.Id)
.Skip(pageSize * page)
.Take(pageSize)
.ToList();
这里,W值是空...
var list = db.X.Include("Y").Include("Z.W")
.Select(a => new { a.Id, a.Z})
.OrderBy(c => c.Id)
.Skip(pageSize * page)
.Take(pageSize)
.ToList();
请帮助:)
UPDATE 1
public class academy
{
public int Id { get; set; }
[StringLength(255)]
[Index(IsUnique = true)]
public string Name { get; set; }
public string Logo { get; set; }
[Required]
public Owner owner { get; set; }
public List<location> Location { get; set; }
}
public class location
{
public int Id { get; set; }
public string Latitude { get; set; }
public string Longitude { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string Neighborhood { get; set; }
public string Street { get; set; }
public academy Academy { get; set; }
public List<stadium> Stadiums { get; set; }
public List<Administrators> Administrators { get; set; }
public List<addition> Addition { get; set; }
public List<Pricing> Pricing { get; set; }
public List<time_frame> TimeFrames { get; set; }
[NotMapped]
public string Details {
get { return (City + " - " + Street); }
}
}
public class Pricing
{
public int Id { get; set; }
public double Price { get; set; }
public double? PriceAfterOffer { get; set; }
public DateTime? StartDate { get; set; }
public DateTime? EndDate { get; set; }
public location Location { get; set; }
public players_capacity StadiumCapacity { get; set; }
}
public class players_capacity
{
public int Id { get; set; }
[StringLength(255)]
[Index(IsUnique = true)]
public string Capacity { get; set; }
}
var list = db.locations
.Select(a => new { a.Id, a.City, a.Region, a.Street, a.Latitude, a.Longitude, a.Pricing, a.Academy })
.OrderBy(c => c.Id)
.Skip(pageSize * page)
.Take(pageSize)
.ToList();
的问题是players_capacity总是空
Z是一个数组,所以我无法写ZW :( – sa94
然后发生了什么'包括(“ZW “)'意思是在你原来的例子中做的? – Dai
Z在一个对象中,但X有一个Z数组。 – sa94