0
モデルをビューにマップしようとしていますが、AutomapperがIEnumerableを認識しないため、すべての要素を表示しようとしているときにエラーが表示されます。 FixedAssetsをFixedAssetsViewに、FixedAssetsViewをFixedAssetsにマップしようとすると、エラーが表示されます。ここでAutomapper:エラーマッピングタイプ。マッピングの種類:IEnumerable`1 - > IEnumerable`1
は私がマップしようとしているオブジェクトです:
FixedAssets
public class FixedAssets : IEntityBase
{
public int ID { get; set; }
public string name { get; set; }
public virtual ICollection<Category> category { get; set; }
public string serialNo { get; set; }
public string provider { get; set;
public DateTime acquisitionDate { get; set; }
public DateTime warrantyEnd { get; set; }
public int inventoryNo { get; set; }
public string allocationStatus { get; set; }
public string owner { get; set; }
public DateTime allocationDate { get; set; }
public string serviceStatus { get; set; }
public string serviceResolution { get; set; }
public FixedAssets()
{
this.category = new HashSet<Category>();
}
}
FixedAssetsView
public class FixedAssetsView
{
public int ID { get; set; }
public string name { get; set; }
public virtual ICollection<CategoryView> category { get; set; }
public string serialNo { get; set; }
public string provider { get; set; }
public DateTime acquisitionDate { get; set; }
public DateTime warrantyEnd { get; set; }
public int inventoryNo { get; set; }
public string allocationStatus { get; set; }
public string owner { get; set; }
public DateTime allocationDate { get; set; }
public string serviceStatus { get; set; }
public string serviceResolution { get; set; }
}
カテゴリー
public class Category : IEntityBase
{
public int ID { get; set; }
public string categoryName { get; set; }
public virtual ICollection<FixedAssets> fixedasset { get; set; }
public Category()
{
this.fixedasset = new HashSet<FixedAssets>();
}
}
CategoryView
public class CategoryView
{
public int ID { get; set; }
public string categoryName { get; set; }
public virtual ICollection<FixedAssetsView> fixedasset { get; set; }
}
Automapper構成
Mapper.Initialize(x =>
{
x.CreateMap<FixedAssets, FixedAssetsView>();
x.CreateMap<FixedAssetsView, FixedAssets>();
x.CreateMap<Category, CategoryView>();
x.CreateMap<CategoryView, Category>();
});
私はMyGetから最新のビルドでエラーが表示されていないが、別の答えが適用される場合があります。 [ここ](https://stackoverflow.com/questions/45298110/how-to-ignore-property-of-property-in-automapper-mapping/45300519#45300519)を参照してください。 –
[AutoMapperマッピングでプロパティのプロパティを無視する方法は?](https://stackoverflow.com/questions/45298110/how-to-ignore-property-of-property-in-automapper-mapping) –