我的 azure 模型中有三个模型。一种模型基本上映射了其他两种模型。这是我的模型
public class Organization : EntityModel
{
public String Id
{
get
{
return this.RowKey;
}
set
{
this.RowKey = value;
}
}
......
}
public class OrganizationGroup : EntityModel
{
public String Id
{
get
{
return this.RowKey;
}
set
{
this.RowKey = value;
}
}
.......
}
现在这是映射类
class OrganizationGroupMapping : EntityModel
{
public String OrganizationId
{
get
{
return this.PartitionKey;
}
set
{
this.PartitionKey = value;
}
}
public String OrganizationGroupId
{
get
{
return this.RowKey;
}
set
{
this.RowKey = value;
}
}
....
}
现在我正在尝试创建一个函数,该函数将为我提供特定组织组中的所有组织。我可以使用 for 循环,我现在正在这样做
public IEnumerable<Organization> GetOrganizations()
{
List<Organization> org = new List<Organization>();
foreach (OrganizationGroupMapping ogm in OrganizationGroupMapping.GetByOrganizationGroupId(Id))
{
org.Add(ogm.GetOrganization());
}
return org;
}
上面的函数是从 OrganizationGroup 类调用的。我正在尝试使用 linq,因为它看起来更干净。但不知道该怎么做。在这方面有什么帮助吗?
最佳答案
您只需使用 System.Linq.Select 这将创建一个隐式类型为 GetOrganization()
的新对象。
public IEnumerable<Organization> GetOrganizations()
{
var organizations = OrganizationGroupMapping.GetByOrganizationGroupId(Id)
.Select(org => ogm.GetOrganization());
return organizations;
}
关于c# - 嵌套 Linq 查询 Microsoft Azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34264392/