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; }
}
我的域和视图类...
以及
用于映射扩展功能
public static TModel ToModel<TModel,TEntity>(this TEntity entity)
where TModel:IBaseViewModel where TEntity:IEntity
{
return Mapper.Map<TEntity, TModel>(entity);
}
我使用方法如下:
City city = GetCity(Id);
CityModel model = f.ToModel<CityModel, City>();
但是它太长了,我能像下面这样写吗?
City city = GetCity(Id);
CityModel model = f.ToModel();
这是可能的吗?