如何在使用 'expand' 时仅包含一个 属性
How to include only a single property when using 'expand'
我有一个订单table要查询。其中一个属性是 "UserId",它变成了用户的导航 属性。
我可以查询它以获取订单和关联的用户。但是,我不想要整个用户实体,只想要用户名 属性.
如何轻而易举地构建该查询?
类似于:
let query = new breeze.EntityQuery()
.from("orders")
.expand("user.userName");
我试过了,但是 returned 对象实际上不是实体,但 return 只是用户名:
let query = new breeze.EntityQuery()
.from("cases")
.select("field1, field2, user.userName");
还有其他方法吗?请注意,我在背面使用 EF。
我为此找到的最佳解决方案是创建一个 "virtual entity",它只包含我想要的两个字段。换句话说,我将 AspNetUsers 作为一个 table 与其对应的实体。然后我有第二个代码优先实体,它仅包含 ID 和用户名:
[Table("AspNetUsers")]
public partial class User
{
[Key]
[Column("Id")]
public string AspNetUserId { get; set; }
[StringLength(256)]
public string UserName { get; set; }
}
然后我可以将它用作其他 table 中的关系,并像另一个 table 一样包含它。
我有一个订单table要查询。其中一个属性是 "UserId",它变成了用户的导航 属性。
我可以查询它以获取订单和关联的用户。但是,我不想要整个用户实体,只想要用户名 属性.
如何轻而易举地构建该查询?
类似于:
let query = new breeze.EntityQuery()
.from("orders")
.expand("user.userName");
我试过了,但是 returned 对象实际上不是实体,但 return 只是用户名:
let query = new breeze.EntityQuery()
.from("cases")
.select("field1, field2, user.userName");
还有其他方法吗?请注意,我在背面使用 EF。
我为此找到的最佳解决方案是创建一个 "virtual entity",它只包含我想要的两个字段。换句话说,我将 AspNetUsers 作为一个 table 与其对应的实体。然后我有第二个代码优先实体,它仅包含 ID 和用户名:
[Table("AspNetUsers")]
public partial class User
{
[Key]
[Column("Id")]
public string AspNetUserId { get; set; }
[StringLength(256)]
public string UserName { get; set; }
}
然后我可以将它用作其他 table 中的关系,并像另一个 table 一样包含它。