我正在尝试将对象从我的实体框架映射到对象。一切正常,直到我必须列出对象。我收到一条错误消息,说我应该使用mapcomplex而不是地图。不幸的是,我找不到该功能的任何文档。
完整课程:
using Cld.Domain.DataService.Contract.Filter;
using Cld.Domain.DataService.Contract.Model;
using Cld.Domain.DataService.Service.Model;
using Core.Data;
using System.Collections.Generic;
using System.Linq;
namespace Cld.Domain.DataService.Service.Repositories
{
internal class ConditRepository : RepositoryBase<CONDIT, Condit, string>,
ISearchableRepository<CONDIT, Condit, ConditFilter>
{
public static readonly IMapping<CONDIT, Condit> ConditMap = new Mapping<CONDIT, Condit>()
.Maps(entity => entity.ID, contract => contract.Id)
.Maps(entity => entity.LIBELLE_D, contract => contract.LabelD)
.Maps(entity => entity.LIBELLE_E, contract => contract.LabelE)
.Maps(entity => entity.LIBELLE_F, contract => contract.LabelF)
.Maps(entity => entity.LIBELLE_N, contract => contract.LabelN)
.Maps(entity => entity.TRACKURL, contract => contract.TrackUrl)
.Maps(entity => entity.CODE, contract => contract.Code)
.Maps(entity => entity.CUSTID, contract => contract.Custid)
.Maps(entity => entity.NUMERO, contract => contract.Number)
.Maps(entity => entity.SCAC, contract => contract.Scac)
.Maps(entity => entity.SERVIID, contract => contract.ServiId)
.Maps(entity => entity.SHIPORDER, contract => contract.ShipOrder)
.Maps(entity => entity.REQTIME, contract => contract.RequestedDateTime)
.Maps(entity => entity.OutputPath, contract => contract.OutputPath)
.Maps(entity => entity.PACTYPs.Select(x => x.ID).ToList(), contract => contract.listPacktypes)
;
}
}
然后是来自EF的课程:
namespace Cld.Domain.DataService.Service.Model
{
using System;
using System.Collections.Generic;
public partial class CONDIT
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public CONDIT()
{
this.SHIPMENTs = new HashSet<SHIPMENT>();
this.PACTYPs = new HashSet<PACTYP>();
}
public string LIBELLE_F { get; set; }
public string LIBELLE_N { get; set; }
public short NUMERO { get; set; }
public string ID { get; set; }
public string LIBELLE_E { get; set; }
public string LIBELLE_D { get; set; }
public string CUSTID { get; set; }
public string SERVIID { get; set; }
public string SCAC { get; set; }
public string CODE { get; set; }
public string TRACKURL { get; set; }
public int SHIPORDER { get; set; }
public System.TimeSpan REQTIME { get; set; }
public string OutputPath { get; set; }
public byte[] timestamp_column { get; set; }
public bool Active { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SHIPMENT> SHIPMENTs { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<PACTYP> PACTYPs { get; set; }
}
}
最后是我试图将其放入的合同:
using Cld.Core.ContractFramework;
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace Cld.Domain.DataService.Contract.Model
{
[DataContract]
public class Condit : IEntity<string>
{
[DataMember]
public string Id { get; set; }
[DataMember]
public string LabelF { get; set; }
[DataMember]
public string LabelN { get; set; }
[DataMember]
public string LabelE { get; set; }
[DataMember]
public string LabelD { get; set; }
[DataMember]
public short Number { get; set; }
[DataMember]
public byte[] Timestamp { get; set; }
[DataMember]
public string Custid { get; set; }
[DataMember]
public string ServiId { get; set; }
[DataMember]
public string Scac { get; set; }
[DataMember]
public string Code { get; set; }
[DataMember]
public string TrackUrl { get; set; }
[DataMember]
public int ShipOrder { get; set; }
[DataMember]
public TimeSpan RequestedDateTime { get; set; }
[DataMember]
public string OutputPath { get; set; }
[DataMember]
public List<int> listPacktypes { get; set; }
}
}
一个同事登录,我设法问了他这个问题。
这是结果:
.MapComplex((entity, contractEntity, synchronizer) =>
{
contractEntity.listCondits = entity.CONDITs.Select(x => x.ID).ToList();
});
实体会自动采用原始类型,contractEntity会采用您要将信息放入的类型,我不知道同步器是什么。从那里,您可以按需操作它们。因此,在这种情况下,我通过使用原始实体中的信息填充合同实体的listCondits来修改了合同实体。
对不起,我的同事应该离开了,所以没有重新连接。