0
當我使用LINQ從表中檢索數據時,所有列都有值。但之後,我把它映射到我的模型的一些字段映射null.The奇怪的部分是,這是不是所有的表Automaapper無法映射少量字段。並輸入空值到這些字段
這是代碼
var city = db.tbl_city.ToList();
AutoMapper.Mapper.CreateMap<tbl_city, ModelCities>();
var CityVieModel = AutoMapper.Mapper.Map<List<tbl_city>, List<ModelCities>>(city);
代碼自定義模型發生
public class ModelCities
{
public int CityId { get; set; }
public string CityName { get; set; }
}
代碼在EDMX表城市
public partial class tbl_city
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public tbl_city()
{
this.tbl_areas = new HashSet<tbl_areas>();
}
public int CityId { get; set; }
public string Cityame { get; set; }
public int StateId { get; set; }
public Nullable<bool> IsAlias { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<tbl_areas> tbl_areas { get; set; }
public virtual tbl_state tbl_state { get; set; }
}