如何在不使用IgnoreAllPropertiesWithAnInaccessibleSetter()的情况下自动忽略映射包?
cfg.CreateMap<Dto, InternetContract>();
public class InternetContract
{
public virtual string Package { get;protected set; }
}
public class Dto
{
public string Package { get; set; }
}
我正在用net core 2.0做一个Entity Framework应用程序。
我使用AutoMapper将数据从一个实体复制到另一个实体。
public class Entity1
{
public int OrderID { get; set; }
public int MarketID { get; set; }
}
public class Entity2
{
[Key]
public int MarketOrderID { get; set; }
public int OrderID { get; se
如果源对象为空,是否可以将AutoMapper配置为返回目标类型的新实例?
Source source = null;
Dest d1 = AutoMapper.Mapper.Map<Source, Dest>(source);
// d1 == null
// I'm looking for a way to configure AutoMapper to
// eliminate this code:
Dest d2 = AutoMapper.Mapper.Map<Source, Dest>(source) ?? new Dest();
我正在合并具有列表成员的对象。我告诉AutoMapper忽略null源成员,但是当我合并一个具有null集合的对象时,目标get是一个空集合(即使它在映射之前有项)。
有没有关于如何防止这种情况的想法?
ConfigurationInfo template1 = new ConfigurationInfo() {
Columns = null //1st templates list of columns is null
};
ConfigurationInfo template2 = new Configuration
这里的目标是忽略空源值,而不要求源对象拥有目标对象所具有的所有字段。只有当所有字段在对象之间匹配时,才能防止null。
public class ApiStudent {
public long Id { get; set; }
public string Name { get; set; }
}
public class DomainStudent {
public long Id { get; set; }
public string Name { get; set; }
public long SchoolId { get; set
我有以下两个POCOs: private class Person
{
public string Name { get; set; }
public int? Age { get; set; }
}
private class PersonDto
{
public string Name { get; set; }
public int? Age { get; set; }
} 在我的应用程序中,我希望实现这样的标准行为:当映射为空的值时,它们不会覆盖它们的目标。这是我试图执行的代码: var mapper = new MapperConfiguratio
我想用AutoMapper映射Order类:
class Order
{
public int Id { get; set; }
public int Quantity { get; set; }
public Product Product { get; set; }
}
产品类:
class Product
{
public int Id { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
}
我为Order类和Product创建了AutoM
我有一系列相互关联的类。像这样:
public class Patient : Entity
{
public virtual string FirstName { set; get; }
public virtual OfficeBranch OriginalOfficeBranch { set; get; }
}
public class OfficeBranch : Entity
{
public virtual string Title { set; get; }
}
和DTO:
public class PatientDto : BaseGeneralDto
在接下来的一两个星期里,我们的代码中开始出现一个奇怪的错误。我试图找出映射失败的根本原因。最内在的例外是令人费解的:Type 'System.String' does not have a default constructor。
我不明白什么是例外告诉我的。你能解释一下发生了什么吗?也许我可以解决这个问题?
映射器在泛型方法中使用:
public TEntity UpdateWithHistory<TEntity>(TEntity entity, int? entityID, int? interviewID)
where TEntity : class
{
我使用AutoMapper将一个ViewModel映射到一个模型。但是,如果对应的源属性是null,则不希望映射属性。
我的源类如下:
public class Source
{
//Other fields...
public string Id { get; set; } //This should not be mapped if null
}
目标类是:
public class Destination
{
//Other fields...
public Guid Id { get; set; }
}
下面是我如何配置映射器:
Mapper.Initi
想知道处理这个问题的最佳方法:
public class SrcClass{
public int? Value1 {get;set;}
public int? Value2 {get;set;}
}
public class DestClass{
public DestClass(int? value1 = 1){
Value1 = value1
}
public int Value1 {get;set;}
public int Value2 {get;set;
}
Mapper.createMap<SrcClass
我有下面的场景。
public class DictionaryEntity
{
public virtual string DictionaryName { get; set; }
public virtual IList<DictionaryRecordEntity> DictionaryRecord { get; set; }
}
public class DictionaryDto
{
public string DictionaryName { get; set; }
public IList<DictionaryRecor
我使用AutoMapper将DTO映射到实体。
在创建映射时,我总是忽略实体之间的关系,这通常会导致很长很长的列表。这就是:
Mapper.CreateMap<CUSTOMER_DTO, CUSTOMER_ENTITY>()
.ForMember(m => m.ORDERS, o => o.Ignore())
.ForMember(m => m.PAYMENT_METHODS, o => o.Ignore());
// And on and on!
有没有一种方法我可以直接指示AutoMapper忽略我实体中的每一个关系?非常感谢。
我对Automapper有意见。我的映射调用看起来如下:
var dataContracts = MapperManager.Mapper.Map<List<Employee>, List<EmployeeDTO>>(entities.ToList());
实体是IQueryable<Employee>
在我的Mapper助手类中,我有:
public class MapperManager
{
public static MapperConfiguration MapperConfiguration { get; set; }
我使用Automapper将具有空集合的类映射到具有相同集合的目标。我需要目标集合也是空的。
配置文件类上有一个名为AllowNullCollections的属性。这并不影响地图的绘制。如果我将cfg.AllowNullCollections设置为True,则映射将目标集合保留为null (如我所愿)。
我不能将系统中所有映射的AllowNullCollections设置为True,它只能应用于我的配置文件。
using System.Collections.Generic;
using AutoMapper;
using NUnit.Framework;
using Assert = NUn
关于Automapper映射定义,我有一个相当简单的问题。我的意图是通过Automapper深入克隆一个对象,同时忽略'Id‘属性,这就是为什么我选择它来自定义映射。
public interface IEntity<T>
{
T Id { get; }
}
public abstract class Entity : IEntity<Guid>
{
public Guid Id { get; set; }
}
我的所有实体都是从Entity类派生的,我只是想忽略对象嵌套层次结构中的所有Id属性,而不对映射定义如此明确。
到目前为止,我已经提出
我正在努力让AutoMapper工作,并且真正坚持完成一项简单的任务。我在用户实体中定义了一个复杂类型:
[ComplexType]
public class CustomerProfile
{
public string FirstName { get; set; }
public string LastName { get; set; }
// ...
}
public class User
{
public long Id {get; set;}
public
下面是我的数据传输对象
public class LoadSourceDetail
{
public string LoadSourceCode { get; set; }
public string LoadSourceDesc { get; set; }
public IEnumerable<ReportingEntityDetail> ReportingEntity { get; set; }
}
public class ReportingEntityDetail
{
public string ReportingEntityCode { get; set
AutoMapper似乎不映射空可空值。只有当可空值为空时,它才会映射属性。
如何告诉AutoMapper总是将空值(任何类型的)从源映射到目的地?
编辑:
AssignableMapper位于NullableMapper之前,如果源为null,它将防止可空类型被映射。
我在一开始就添加了这个代码片段来插入NullableMapper。
container.RegisterSingle(() =>
{
// we need to add a nullable mapper to ensure Nullable<value&g
出于某种原因,AutoMapper给了我一个我需要的类型列表,其中所有属性都是0或null。当我调试数据时,我看到我的列表中包含所有包含数据的对象和属性。但是.Map()给出了一个列表,其中没有属性中的数据(但包含正确数量的对象)。我是AutoMapper的新手,但这看起来确实很奇怪。有什么建议吗?
public static IMapper Initialize()
{
var config = new MapperConfiguration(cfg => {
cfg.CreateMap<PlantSelectResult, IPl
假设我有类似的类结构
public class Entity
{
public List<EntityChild> Children { get; set; }
}
public class EntityChild
{
public int Id { get; set; }
public string Name { get; set; }
}
我希望使用AutoMapper将AutoMapper映射到类EntityDto并进行反向映射。
public class EntityDto
{
public List<int> EntityCh
我有一个在v10版本上工作的Automapper安装程序,但是自从我将它更新到最新的v11之后,它就不再工作了。我不知道会有什么问题。源文件和目标文件都是相似的。希望有人能帮我。
当automapper启动时弹出的消息是
Incorrect number of arguments supplied for call to method Rig.Commercial.Reservation.Contract.V1.Generic.GeoJson.GeojsonPoint get_Item(Int32)' (Parameter 'property')
这是我的配置文件中的地
所以我有这个WebApiPrice.Web.Api.Models.Category类
/*
* Service model class, that will represent categories
*/
using System;
using System.Collections.Generic;
namespace WebApiPrice.Web.Api.Models
{
public class Category
{
private List<Link> _links;
public long Categor
我有一个业务实体对象,我需要使用AutoMapper映射到WCF服务的数据契约对象,但是我在'MemberDataList‘(数据访问层)有相同版本的数据实体类“成员”时出错了,这是我用来映射到业务对象类及其工作状态的,但不知道为什么会出现问题。
源类
public class Member
{
public int MemberID { get; set; }
public string Title { get; set; }
public string Surname { get; set; }
public string Forename