E1.03 Php Symfony Doctrine vs. Entity Framework. Flat data selection issue. (Wpf, Xamarin, Angular SPA, Reactjs SPA) - chempkovsky/CS2WPF-and-CS2XAMARIN GitHub Wiki
Important for us difference: Symfony Doctrine does not select flat data if the Entity has many-to-one relation.
Let's return to the "E1.02 Php Symfony Doctrine vs. Entity Framework. Flat data insertion issue."-article only for the Entity definitions.
Here is a task
Supppose we need to return to the client Dialect with one additional CountryName-property. With Entity Framework we use the following code
// We decalre addtional class which is not an Entity
public class LitDialectView {
[JsonProperty(PropertyName = "dialectId")]
[Required]
[Display(Description="Dialect Id",Name="Dialect Id",Prompt="Dialect Id",ShortName="Id")]
[StringLength(14,MinimumLength=5)]
public System.String DialectId { get; set; }
[JsonProperty(PropertyName = "dialectName")]
[Required]
[Display(Description="Dialect Name (no more than 40 characters in length)",Name="Dialect Name",Prompt="Enter Dialect Name",ShortName="Dialect")]
[StringLength(52,MinimumLength=2)]
public System.String DialectName { get; set; }
[JsonProperty(PropertyName = "iso3CntrRef")]
[Required]
[Display(Description="Country Iso 3 code",Name="Country Iso 3 code",Prompt="Enter Country Iso 3 code",ShortName="Country Iso 3")]
[StringLength(3,MinimumLength=3)]
public System.String Iso3CntrRef { get; set; }
[JsonProperty(PropertyName = "iso2CntrRef")]
[Required]
[Display(Description="Country Iso 2 code",Name="Iso 2 code",Prompt="Enter Country Iso 2 code",ShortName="Country Iso 2")]
[StringLength(3,MinimumLength=2)]
public System.String Iso2CntrRef { get; set; }
[JsonProperty(PropertyName = "cCountryName")]
[Required]
[Display(Description="Country Name (no more than 30 characters in length)",Name="Country Name",Prompt="Enter Country Name",ShortName="Country")]
[StringLength(40,MinimumLength=3)]
public System.String CCountryName { get; set; }
}
// And here is a code to select flat data
List<LitDialectView> result = db.LitDialectDbSet
.Where(p => p.Country.CountryName == "Afar (Djibouti)")
.Select(itm => new LitDialectView() {
DialectId = itm.DialectId,
DialectName = itm.DialectName,
Iso3CntrRef = itm.Iso3CntrRef,
Iso2CntrRef = itm.Iso2CntrRef,
CCountryName = itm.Country.CountryName,
}).ToList();
Using Doctrine you could accomplish the same task with a help of Named Queries. But they say that Named Queries are Deprecated.