在以前的AutoMapper版本中,我曾经能够像这样配置AutoMapper:
public static class AutoMapperFactory
{
public static IConfigurationProvider CreateMapperConfiguration()
{
var config = new MapperConfiguration(cfg =>
{
//Scan *.UI assembly for AutoMapper Profiles
var assembl
我在PCL中使用Automapper已经3年了,一切都很好。
但是,由于4.2.1版本,当我试图在PCL中安装它时,我会得到以下错误:
Could not install package 'AutoMapper 4.2.1'.
You are trying to install this package into a project that targets
'portable-net45+win+wp80+MonoTouch10+MonoAndroid10+xamarinmac20+xamarinios10',
but the package does no
我有一个应用程序,我想在其中使用最新版本的AutoMapper。我还使用第三方程序集,它本身使用AutoMapper 3.1.1.0。
如果允许第三方程序集使用最新版本,它将尝试调用一个不再存在的方法,并得到以下结果:
System.TypeInitializationException: 'The type initializer for 'Sif.Framework.Service.Mapper.MapperFactory' threw an exception.'
Inner Exception
MissingMethodException: Method
AutoMapper没有本地方法来更新需要删除实例、添加或更新的嵌套列表吗?
我在使用EF的ASP.Net核心应用程序中使用ASP.Net将我的API资源映射到我的模型中。这对于我的大多数应用程序来说都很好,但是我对我的解决方案并不满意,因为我的解决方案是更新映射的嵌套列表,其中列出的实例需要持续存在。我不想覆盖现有列表,我希望删除不再在传入资源中的实例,添加新实例,并更新现有实例。
模型:
public class MainObject
{
public int Id { get; set; }
public List<SubItem> SubItems { ge
摘要:--我在调试一组AutoMapper映射时遇到了困难,需要一种更“外科”的方法来定位要修复的坏映射。
问题: InvalidOperationException中的异常消息是:
No coercion operator is defined between types 'My.Models.WorkViewModel' and 'My.Model.Work'.
抛出异常时的堆栈跟踪在调试器中是可见的,并且是简单和直接的,但没有太大帮助:
ex.StackTrace:
at AutoMapper.MapperConfiguration.Generate
我使用的是Asp.NET核心2.2。我有两个领域模型,名为Product和ProductType
这是产品领域模型
public class Product
{
public int ProductID { get; set; }
public int ProductName { get; set; }
public string ProductImage { get; set; }
public int ProductTypeID { get; set; }
[ForeignKey("ProductTypeID")]
publ
在接下来的一两个星期里,我们的代码中开始出现一个奇怪的错误。我试图找出映射失败的根本原因。最内在的例外是令人费解的:Type 'System.String' does not have a default constructor。
我不明白什么是例外告诉我的。你能解释一下发生了什么吗?也许我可以解决这个问题?
映射器在泛型方法中使用:
public TEntity UpdateWithHistory<TEntity>(TEntity entity, int? entityID, int? interviewID)
where TEntity : class
{
我正在寻找用Automapper处理这个问题的最好方法
我的简化域模型(所有ID都由DB自动生成):
public class Product
{
public long Id { get; set; }
public List<OrderProduct> OrderProducts { get; set; }
}
public class Order
{
public long Id { get; set; }
public List<OrderProduct> OrderProducts { get; set; }
}
publi
如果源对象为空,是否可以将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();
我有一个简单的数据模型:
// Model
public class Address
{
public string Street { get; set; }
public string City { get; set; }
public string State { get; set; }
public string ZipCode { get; set; }
.... Another values here ....
}
public class Person
{
public string FirstName { get; set; }
来源模型:
public class ExampleModel
{
public int Id { get; set; }
public float Something { get; set; }
public string Info { get; set; } = "";
}
public class ExampleModelContainer
{
public int Id { get; set; }
public ExampleModel Model { get; set; } = null!;
}
public class L
假设我有这样一个类:
public class Account
{
public int AccountID { get; set; }
public Enterprise Enterprise { get; set; }
public List<User> UserList { get; set; }
}
当我使用AutoMapper映射Account类时,我也希望它映射Enterprise类,以及返回对象中的用户列表(UserList)。怎样才能让AutoMapper做到这一点呢?
谢谢!
我想创建没有依赖注入的AutoMapper的静态实现。我使用的是ASP.NET Core2.2和AutoMapper 9。我找到了类似的主题: How to use AutoMapper 9.0.0 in Asp.Net Web Api 2 without dependency injection? 有没有更简单的方法可以在没有依赖注入的情况下创建静态实现?
假设我有类似的类结构
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
为什么Automapper不使用SourceMember属性映射到雇员?如果我将名称与名称相匹配,它就会工作:
不管用:
是否有效:
using AutoMapper;
using AutoMapper.Configuration.Annotations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AutoMapperConsole1
{
[AutoMap(typeof(P
我正在研究一个现有的解决方案。该解决方案使用温莎IoC。我有一个AutomapperMappings.cs类,如下所示:
public class AutoMapperMappings
{
public static void Configure()
{
AutoMapper.Mapper.Configuration
.CreateMap<LatestUpdateModel, LatestUpdate>();
AutoMapper.Mapper.Configuration
.CreateMap<
我试图在我的MVC MVVM应用程序中将我的域模型映射到viewModels。这是我的Auto配置代码
public class AutoMapperConfiguration
{
public static void Configure()
{
Mapper.Initialize(x =>
{
x.AddProfile<BookStoreMappingProfile>();
});
}
}
测绘概况:
public class BookStoreMappingProfile: P
我想使用自动映射程序将ExpandoObject转换为标准对象。问题是需要将一些属性从字符串转换为DateTime,其中DateTime字符串是非标准的。
下面是一些示例代码:
class Program
{
public static void Main(string[] args)
{
dynamic src = new ExpandoObject();
src.Name = "Joe";
src.MyDateTime = "0619201359"; //mmddyyhhmm format
First
我已经创建了这个 ,它只需要是F5就可以命中这个错误,所以您应该可以很容易地尝试这个错误。这个问题中的所有环节都会导致回购。
代码流
我的控制器中的是我希望给前端开发人员包括他们所需要的关系的权力的地方。
// The included tables I want to control from my controller
Expression<Func<CompanyDto, object>>[] includes = { x => x.Employees, x => x.Cars };
var companyDto2 = await ser
AutoMapper似乎不映射空可空值。只有当可空值为空时,它才会映射属性。
如何告诉AutoMapper总是将空值(任何类型的)从源映射到目的地?
编辑:
AssignableMapper位于NullableMapper之前,如果源为null,它将防止可空类型被映射。
我在一开始就添加了这个代码片段来插入NullableMapper。
container.RegisterSingle(() =>
{
// we need to add a nullable mapper to ensure Nullable<value&g