Ich habe 3 Tabellen Kontinent, Land und Stadt. Ich muss ein Objekt vom Typ Kontinent machen, dessen Länder und Länder ihre Städte haben.Linq: Wie man ein Objekt von linq Ergebnis
Kontinent -> Land -> Stadt wie diese. Europa -> Deutschland -> Frankfurt am Main, Berlin, etc ..
Mein Code:
public partial class Continent
{
public Continent()
{
this.Countries = new HashSet<Country>();
}
public int ContinentId { get; set; }
public string ContinentName { get; set; }
public virtual ICollection<Country> Countries { get; set; }
}
public partial class Country
{
public Country()
{
this.Cities = new HashSet<City>();
}
public int CountryId { get; set; }
public string CountryName { get; set; }
public Nullable<int> ContinentId { get; set; }
public virtual ICollection<City> Cities { get; set; }
public virtual Continent Continent { get; set; }
}
public partial class City
{
public int CityId { get; set; }
public string CityName { get; set; }
public int CountryId { get; set; }
public virtual Country Country { get; set; }
}
var Result = (from a in db.Continents
join b in db.Countries
on a.ContinentId equals b.ContinentId
join c in db.Cities on b.CountryId equals c.CountryId
where a.ContinentId == 1
select new
{
ContinentName = a.ContinentName,
CountryName = b.CountryName,
CityName = c.CityName
});
Dies ist das Ergebnis:
Ich brauche, um ein Objekt zu machen von Geben Sie Kontinent ein, der seine eigenen Grafschaften und Städte enthält
* ich ein Objekt * machen müssen und was ist Ihre Frage? –