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();
是可能的吗?
感谢丹尼尔,它为我好:) – tobias 2012-03-22 13:02:49
@tobias - 我忘了演员。 – 2012-03-22 13:03:26