valueinjecter

How do I stop ValueInjecter from mapping null values?

夙愿已清 提交于 2019-12-10 09:33:23
问题 I am using ValueInjecter to map two identical objects. The problem I am having is that ValueInjector copies null values from my source over my target. So I am loosing lots of data to null values. Here's an example of my object which is sometimes only half filled out which results in its null values overwriting the target object. public class MyObject() { public int ID { get; set; } public string Name { get; set; } public virtual ICollection<OtherObject> OtherObjects { get; set; } } to

How do I create a custom value injection to map my entity to my view model? Attempt included

廉价感情. 提交于 2019-12-06 13:17:58
I'm trying to use the ValueInjector (latest version from NuGet) to inject my view model with data from my EntityFramework Code First object. I'll want to do the reverse of this as well, but this is the attempt I'm starting with. I've researched the various mappings and have tried many of them. I haven't found one that does what I need and I think my need is a rather basic one (there are several of these questions on SO and each seems to get a different answer, which is fine.). I've really tried to do my due diligence on this. I've googled and trolled CodePlex and downloaded the ProDinner

How do I stop ValueInjecter from mapping null values?

[亡魂溺海] 提交于 2019-12-05 17:40:34
I am using ValueInjecter to map two identical objects. The problem I am having is that ValueInjector copies null values from my source over my target. So I am loosing lots of data to null values. Here's an example of my object which is sometimes only half filled out which results in its null values overwriting the target object. public class MyObject() { public int ID { get; set; } public string Name { get; set; } public virtual ICollection<OtherObject> OtherObjects { get; set; } } to.InjectFrom(from); You need to create a custom ConventionInjection in this case. See example #2: http:/

Using ValueInjecter to map between objects with different property names

左心房为你撑大大i 提交于 2019-12-03 03:08:39
How do I map a property from an object to another object with a different property name? I have a Product class that looks like this: public class Product : IEntity { public int Id { get; set; } public string Name { get; set; } } And the view model looks like: public class ProductSpecificationAddViewModel { public int ProductId { get; set; } public string ProductName { get; set; } } I need to do the following mapping: Product.Id => ProductSpecificationAddViewModel.ProductId Product.Name =>ProductSpecificationAddViewModel.ProductName Here is my action method: public ActionResult Add(int id) {

omu.valueinjecter deep clone unlike types

假如想象 提交于 2019-11-30 19:43:45
I think I'm missing a simple concept with valueinjecter and/or AutoMapper, but how do you deep clone a parent dto.Entity to biz.Entity and include all children? For example, biz.person.InjectFrom(dto.person) . I want the dto.person.AddressList collection to copy down to biz.person.AddressList collection, even though dto.Address and biz.Address are unlike types, but have the same property names. My thinking is that if the Parent property names are spelled the same, e.g. AddressList, then it wouldn't matter if the 2 underlying objects were of different types. It would still copy same-named

How to deep clone objects containing an IList property using AutoMapper

懵懂的女人 提交于 2019-11-30 17:40:02
I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; set; } public int Prop2 { get; set; } public void AddDetail(Detail detail) { Details.Add(detail); } public void RemoveDetail(Detail detail) { Details.Remove(detail); } public MainData Clone() { Mapper.Reset(); Mapper.CreateMap<MainData, MainData>().ForMember(d => d.Id, o => o.Ignore()); // Mapper

How to deep clone objects containing an IList property using AutoMapper

落花浮王杯 提交于 2019-11-30 16:42:54
问题 I am trying to deep clone the following class using AutoMapper: public class MainData { public MainData() { Details = new List<Detail>(); } public int Id { get; private set; } public DateTime LastUpdate { get; private set; } public IList<Detail> Details { get; private set; } public int Prop1 { get; set; } public int Prop2 { get; set; } public void AddDetail(Detail detail) { Details.Add(detail); } public void RemoveDetail(Detail detail) { Details.Remove(detail); } public MainData Clone() {

omu.valueinjecter deep clone unlike types

▼魔方 西西 提交于 2019-11-30 04:50:41
问题 I think I'm missing a simple concept with valueinjecter and/or AutoMapper, but how do you deep clone a parent dto.Entity to biz.Entity and include all children? For example, biz.person.InjectFrom(dto.person) . I want the dto.person.AddressList collection to copy down to biz.person.AddressList collection, even though dto.Address and biz.Address are unlike types, but have the same property names. My thinking is that if the Parent property names are spelled the same, e.g. AddressList, then it

Copying NHibernate POCO to DTO without triggering lazy load or eager load

空扰寡人 提交于 2019-11-29 14:59:13
I need to create DTOs from NHibernate POCO objects. The problem is that the POCO objects contain dynamic proxies , which should not be copied to the DTO. I eager load all the collections and references I need to transfer in advance, I don't want NHibernate to start loading referenced collections which I did not load in advance. Several similar questions on SO received answers which either: Suggest Session.GetSessionImplementation().PersistenceContext.Unproxy(); Suggest turning off Lazy Loading. In my case the first suggestion is irrelevant, as according to my understanding it causes eager

Successful Model Editing without a bunch of hidden fields

匆匆过客 提交于 2019-11-29 02:56:34
问题 In Short : How do I successfully edit a DB entry without needing to include every single field for the Model inside of the Edit View? UPDATE So I have an item in the DB (an Article). I want to edit an article. The article I edit has many properties (Id, CreatedBy, DateCreated, Title, Body). Some of these properties never need to change (like Id, CreatedBy, DateCreated). So in my Edit View, I only want input fields for fields that can be changed (like Title, Body). When I implement an Edit