可以通过100万种方式做到这一点。
Problem. I have a list of servers which belongs to a country.
各国有许多服务器,因此其导航有两种方式(我认为其名称是)
Now I have a list of servers with there country set and want to group by country so I can get the opposite list.
List of countries with all there servers attached to the ICollection of the Country ( Servers )
var groupBy = list.GroupBy(x => x.Country, x => x, (c, s) => new {c, s});
foreach (var country in groupBy)
{
}
This will almost give me the result I want, but now I have 2 anon types. C which is country and S which is the list of servers.
How can I attach the list of servers to the country object s Collection.
班级类似......简化。
public class Server
{
public short SID { get; set; }
public Country Country { get; set; }
}
public class Country
{
public byte CID { get; set; }
public ICollection<Server> Servers { get; set; }
}
我猜测,我们可以建立一个有信息的新国家,然后把服务器名单放在建筑商......但我认为这种超技能。
......这种奇迹很简单,但我在这里失去了。
Update
我需要选择所有满足某种条件的服务器。 因此,我有一个国家服务器清单。 现在我刚刚需要改变名单。 能否以其他方式做到这一点?
I m using the Repository Pattern with EF 4 Code First. IRepository I only have the following methods available with a option to eager load a property: Single, SingleOrDefault, Find and FindAll
没有 la的负荷,他们都返回ICollection或一个T。