Please review my code. For every my Entity i've created a service class, where i put all the access methods for this entity.This method are doing the transformation from the Entities to my DTO classes. This methods are called from the Web layer or a bussines method. Am I doing this righth? Or should I do it differently ?
The service method:
public static IEnumerable<OsobaDto> GetNakupyByOsoba(Guid guid)
{
using (FinanceEntities finance = new FinanceEntities())
{
var osoby = from o in finance.OsobaSet
where o.Nakupy.Any(n => n.idnakupu == guid)
select new OsobaDto
{
Id = o.idosoba,
Meno = o.meno,
Priezvisko = o.priezvisko,
Prijem = o.prijem,
Nakupy = o.Nakupy.Select(n => new NakupDto
{
IdNakupu = n.idnakupu,
Cena = n.cena,
Datum = n.datum
})
};
return osoby;
}
}
And the DTO class
public class NakupDto
{
public Guid? IdNakupu
{
get;
set;
}
public Decimal Cena
{
get;
set;
}
public DateTime Datum
{
get;
set;
}
public IEnumerable<OsobaDto> Osoby
{
get;
set;
}
public OsobaDto Platil
{
get;
set;
}