automapper

Using DTO's with OData & Web API

你。 提交于 2020-01-01 08:41:06
问题 Using Web API and OData, I have a service which exposes Data Transfer Objects instead of the Entity Framework entities. I use AutoMapper to transform the EF Entities into their DTO counter parts using ProjectTo() : public class SalesOrdersController : ODataController { private DbContext _DbContext; public SalesOrdersController(DbContext context) { _DbContext = context; } [EnableQuery] public IQueryable<SalesOrderDto> Get(ODataQueryOptions<SalesOrderDto> queryOptions) { return _DbContext

ITypeConverter interface has been changed in AutoMapper 2.0

本小妞迷上赌 提交于 2020-01-01 04:20:29
问题 The ITypeConverter interface has been changed to have a "TDestination Convert(ResolutionContext context)" instead of "TDestination Convert(TSource source)" for the Convert method. http://automapper.codeplex.com/wikipage?title=Custom%20Type%20Converters In my code, now I get this error: 'BusinessFacade.Mappers.DecimalToNullableInt' does not implement interface member 'AutoMapper.ITypeConverter.Convert(AutoMapper.ResolutionContext)' Any good full sample for new mapper like my mappers ? I don't

jsonpacth中文文档(纯机翻如侵权请联系删除)

丶灬走出姿态 提交于 2020-01-01 00:57:11
使用ASP.net Core的JSON补丁 2017年11月29日 由 韦德 · 8评论 JSONPatch是一种以非常明确的方式更新API上的文档的方法。它本质上是一个合同,用于准确描述您希望如何修改文档(例如,将字段中的值替换为另一个值),而不必同时发送其余未更改的值。 JSON补丁请求是什么样的? JSON Patch的官方文档存在于这里: http : //jsonpatch.com/ ,但我们将进行一些挖掘,以了解它在ASP / C#中的工作原理,因为并非所有应用程序都能正常工作。事实上,一项操作还没有成为ASP.net Core的正式版本,但无论如何我们都会快速谈谈它。 对于所有示例,我将针对在C#中看起来像这样的对象编写JSON补丁请求: 1 2 3 4 5 6 public class Person { public string FirstName { get; set; } public string LastName { get; set; } public List<string> Friends { get; set; } } 补丁请求都遵循类似的结构类型。它是数组中“操作”的列表。该操作本身有3个属性。 “op” - 定义您要执行的操作的“类型”。例如,添加,替换,测试等 “path” - 要编辑的对象上属性的“路径”。在上面的示例中,如果我们想要编辑

Automapper merging objects issue

≡放荡痞女 提交于 2019-12-31 07:18:50
问题 After getting automapper to work (previous question), I'm struggling with another problem (took it to another question, so the first one wouldn't be too complicated)... I have next classes: public class Model1 { public string FirstName { get; set; } public string LastName { get; set; } public DateTime BirthDay { get; set; } public int Gender { get; set; } public string NickName { get; set; } } public class Model2 { public bool Married { get; set; } public int Children { get; set; } public

DTO mapping exception with entity in ABP

醉酒当歌 提交于 2019-12-31 03:43:08
问题 I got an error about "mapping" when I try to insert an entity. The insert is made by the Create method of a CrudAppService. My entity inherits from FullAuditedEntity but the related DTO specifies only a few properties. How do I handle this situation? Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map

AutoMapper TypeConverter mapping nullable type to not-nullable type

房东的猫 提交于 2019-12-31 03:38:06
问题 I'm using AutoMapper, and I've registered a TypeConverter to map nullable long values to long values like so: public class NullableLongToLongConverter : TypeConverter<long?, long> { protected override long ConvertCore(long? source) { return source ?? 0; } } This works fine, and automatically picks up any nullable longs being converted to longs. However, I've got some other maps which want to 'convert' nullable longs to nullable longs. These also end up using this type converter. For example,

Automapper complex types mapping exception

◇◆丶佛笑我妖孽 提交于 2019-12-30 11:03:04
问题 I'm trying to implement the AutoMapper for a new module. I have the MVC model at the web site, I'm working on, and it looks like this: public class MvcModel { public Params Params { get; set; } public Steps Steps { get; set; } } public class Params { public int? RequestId { get; set; } public bool NewClient { get; set; } } public class Steps { public Step1 Step1 { get; set; } public Step2 Step2 { get; set; } public Step3 Step3 { get; set; } } public class Step1 { public int Name { get; set; }

Automapper complex types mapping exception

*爱你&永不变心* 提交于 2019-12-30 11:02:13
问题 I'm trying to implement the AutoMapper for a new module. I have the MVC model at the web site, I'm working on, and it looks like this: public class MvcModel { public Params Params { get; set; } public Steps Steps { get; set; } } public class Params { public int? RequestId { get; set; } public bool NewClient { get; set; } } public class Steps { public Step1 Step1 { get; set; } public Step2 Step2 { get; set; } public Step3 Step3 { get; set; } } public class Step1 { public int Name { get; set; }

An exception of type 'AutoMapper.AutoMapperMappingException' occurred in AutoMapper.dll but was not handled in user code

北战南征 提交于 2019-12-30 08:13:47
问题 Somehow my code doesn't work any more (it did work before with the exact same code). This is the problem: The code I'm trying to map some objects to ViewModels with this code: Configuration: Mapper.CreateMap<BookcaseItem, FoundBookcaseItemViewModel>() .ForMember(x => x.Title, opt => opt.MapFrom(src => src.Book.Title)) .ForMember(x => x.Authors, opt => opt.MapFrom(src => src.Book.Authors.Select(x => x.Name).Aggregate((i, j) => i + ", " + j))) .ForMember(x => x.Identifiers, opt => opt.MapFrom

How to marry EntityFramework, Repository, UnitOfWork and Automapper altogether in one MVC application?

ε祈祈猫儿з 提交于 2019-12-30 07:01:10
问题 First I decided to create one Interface called it IDataAccessLayer and started putting everything into it: methods like GetUsers() , GetUser(int id) , GetOrderByNumber(int number) , DeleteOrder(int Id) etc. That worked just perfect at first. But then I realized that the concrete implementation of DataLayer:IDataLayer is growing to big. I decided to cut it into several partial class files. Still I was feeling that I'm doing something really wrong. Then I decided to create interfaces for each