这是我的数据结构:
public class Product
{
// Rest of props
public ICollection<ProductUpdate> ProductUpdate { get; set; }
}
public class ProductUpdate
{
// Rest of props
public Delivery Delivery { get; set; }
}
public class Delivery
{
// Rest of props
public virtual ICollection<DeliveryUsersApprovers> DeliveryUsersApprovers { get; set; }
}
public class DeliveryUsersApprovers
{
// Rest of props
public User User { get; set; }
}
如何编写linq方法语法查询,该查询将从Id
中选择StartDate
,Note
和ProductUpdate
,同时为每行选择ProductUpdate
对应用户,该用户在[ C0]类我想使用DeliveryUsersApprovers
仅获得所需的列来实现它。
我已经尝试过类似的方法,但是那是行不通的:
.Select()
我真的很想深入嵌套道具并为每个
var paymentStatusUpdates = await _dbContext.Product.Include(x => x.ProductUpdate) .Select(x => new SomeCustomClassObjectWithFourProperties { // Read data from ProductUpdate somehow and select Id, Date and Note from ProductUpdate and get User from nested property .Select(y=> new SomeCustomClassObjectWithFourProperties { Id = y.Id, Date=y.StartDate, Note=y.Note, User=? // this is User from very nested prop }) }) .FirstOrDefaultAsync(x => x.Id == productId, cancellationToken); //productId is received in method params
达到User
,所以任何形式的帮助都将非常有用!
谢谢
这是我的数据结构:public class Product {//其余道具public ICollection
使用ProductUpdate
展平SelectMany
集合,然后将每个DeliveryUsersApprovers
映射到包含DeliveryUsersApprovers
和Result
数据的User
对象。