public abstract class Entity : IEntity
{
[Key]
public virtual int Id { get; set; }
}
public class City:Entity
{
public string Code { get; set; }
}
public class BaseViewModel:IBaseViewModel
{
public int Id { get; set; }
}
public class CityModel:BaseViewModel
{
public string Code { get; set; }
}
moje klasy domeny i przeglądanie ...Typowa metoda rozszerzenie dla automapper
i
o przedłużenie odwzorowania
public static TModel ToModel<TModel,TEntity>(this TEntity entity)
where TModel:IBaseViewModel where TEntity:IEntity
{
return Mapper.Map<TEntity, TModel>(entity);
}
i używam jak poniżej
City city = GetCity(Id);
CityModel model = f.ToModel<CityModel, City>();
, ale jego długo
Czy mogę napisać to tak, jak poniżej?
City city = GetCity(Id);
CityModel model = f.ToModel();
czy to możliwe?
dzięki Daniel, jego dobre dla mnie :) – tobias
@tobias - zapomniałem obsady. –