【发布时间】:2014-10-16 05:15:55
【问题描述】:
我想为我的数据创建一个树列表视图。
树应该是这样的
帐户
-> 提供者
-> 帐户
public sealed class AccountRoot
{
public AccountRoot()
{
Providers = new Collection<Hoster>();
}
public long AccountRootId { get; set; }
public ICollection<Hoster> Providers { get; set; }
}
public sealed class Hoster
{
public Hoster()
{
Accounts = new Collection<Account>();
}
[Key]
public long HosterId { get; set; }
public long AccountRootId { get; set; }
public string Name { get; set; }
public ICollection<Account> Accounts { get; set; }
}
public sealed class Account
{
[Key]
public long AccountId { get; set; }
public long HosterId { get; set; }
public Hoster Hoster { get; set; }
public string Name { get; set; }
}
我想订购我的查询。
应该是这样的
帐户
供应商 A-Z
帐户 A-Z
到目前为止我得到的是..
var query = _entity.AccountRoot.Local
.Select(x => new AccountRoot()
{
AccountRootId = x.AccountRootId,
Providers = x.Providers.OrderBy(y => y.Name).ToList()
}).ToList();
缺少的是下一个嵌套集合的orderby。
感谢您的帮助! :-)
【问题讨论】:
-
你为什么选择
Localbtw? -
我的实体是单例的,因为我需要它作为列表...确实尝试过使用短期实体,但没有达到我的目的...谢谢!
-
您需要一个查询来获得最终结果吗?或者您只需要对预先填充的对象(
Locale是ObservableCollection)中的数据进行排序即可达到最终结果?
标签: c# linq entity-framework frameworks entity