配置AutoMapper以将ICollection<DomainModel>映射到ICollection<ViewModel>再到ICollection<object>的最佳/最简单方法是什么
我有一个看起来像这样的DomainModel:
public class DomainModel
{
ICollection<EFEntity> Data;
//other stuff
}
我想把这个DomainModel映射到一个MVC ViewModel:
public class ViewModelWithCollection
{
假设如下所示:
public class ParentSource
{
public Guid parentId { get; set; }
public ICollection<ChildSource> children { get; set; }
}
public class ChildSource
{
public Guid childId { get; set; }
}
public class ParentDestination
{
public Guid parentId { get; set; }
public ICol
对于一些DTO,我有以下接口:
public interface IGalleryView
{
ICollection<IGalleryImageView> Images { get; set; }
}
public interface IGalleryImageView
{
// Some simple properties
}
以及以下具体类型:
public class GalleryView : IGalleryView
{
public GalleryView() {
Images = new List<IGa
因此,我正在使用EF和WebAPI构建REST服务。我有两堂这样的课
public class App
{
[Key]
public int ID {get;set;}
public virtual ICollection<User> Users {get;set;}
}
public class User
{
[Key]
public int ID {get;set;}
public virtual ICollection<App> Apps {get;set;}
}
我可以看到EF正确地创建了表,所有的东西都很漂亮。问题是,我不能通
在json.net JObject中使用AutoMapper时出现反射错误
public class Source
{
public string Key { get; set; }
public JObject Value { get; set; }
}
这就是目标
public class Target
{
public string Key { get; set; }
public JObject Value { get; set; }
}
这是映射
public class SourceTargetMapping
{
public static
在迁移到v2.0之后,我发现了这个问题
我尝试像这样映射属性:
public class SurveyFormView
{
public MultiSelectList Statistics { get; set; }
}
public class SurveyForm
{
ICollection<Statistic> statistics = new List<Statistic>();
public virtual ICollection<Statistic> Statistics
{
get { re
我试图在代码中使用AutoMapper。映射集合时,我得到了以下错误
LINQ到实体不识别方法'System.Collections.Generic.List1[Web.ViewModels.FirmMatterViewModel] Map[ICollection1,List1](System.Collections.Generic.ICollection1Web.Models.FirmMatter)的方法,而且此方法不能转换为存储表达式。
这就是我如何进行映射的代码:
var clientMatters =
from cm in db.ClientMatters
我对从相关域模型返回对象有问题。来自其他模型的对象返回null。
基本上,我试图实现的是返回一个DTO,该DTO具有我希望从相关域模型中得到的字段,而不是将每个字段直接从域模型传递到json。
请看下面的代码,谁能告诉我。
## CourseDomainModels.cs ##
public class CourseDomainModel : IObjectWithState
{
public int Id { get; set; }
public string Name { get; set; }
public Double Duration { get
我已经实现了简单的MVC3应用程序,其中我已经使用automapper将我的数据库表绑定到ViewMode,但我无法使用AutoMapper绑定复杂的ViewModel。
这是我的域类
namespace MCQ.Domain.Models
{
public class City
{
public City()
{
this.AreaPincode = new List<AreaPincode>();
}
public long ID { get; set; }
为了便于讨论,我目前有一个数据对象,我将其命名为foo…
public class Foo
{
public int IndexedKey { get; set;}
public string NonIndexedData {get; set;}
}
我有一个通用的存储库,我想用它来查询这个对象,但是由于对数据库的权限,我不允许执行全表扫描。因此,我的任务是创建安全的查询对象。
public class FooQuery
{
public int IndexedKey
}
通用存储库允许任意谓词,它目前有一个类似于以下内容的实现……
public class FooRep
我正在编写一个使用AutoMapper进行对象映射的ASP.NET Web API服务。我正在针对AbleCommerce购物车软件构建此服务。问题中的服务(目的地)类跟踪用户及其地址。
public class UserModel
{
public int UserID { get; set; }
...
public List<AddressModel> Addresses { get; set; }
}
public class AddressModel
{
public int AddressID { get; set; }
pu
我想在这个实体模型之间创建一个映射:
public class ProductType
{
public int Id { get; set; }
public string Title { get; set; }
public int SortOrder { get; set; }
public ICollection<ProductIdentifierInType> Identifiers { get; set; }
public ICollection<ProductPropertyInType> Properties {
假设我有一个域名:
public class EmbeddedInBar
{
public string Name { get; get; }
public ICollection<int> ListOfInts { get; set; }
}
public class Bar
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<int> ListOfInts { get; set; }
public Embe
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AutoMapper;
namespace TestAutomapper
{
class Program
{
static void Main(string[] args)
{
var config = new MapperConfiguration(cfg => cfg.CreateMap<M
public class Item
{
public string Name { get; set; }
public virtual ICollection<Stock> Stocks { get; set; }
public virtual ICollection<Price> Prices { get; set; }
-- remove some code for brevity --
}
public Stock
{
public int Id { get; set; }
public int ItemId { get; set;
我使用的是OData V4、EF6和MySql 5.6/5.7,型号和表格如下。通过调用odata/Applications,我可以很好地获得Application资源的结果,但是当我展开roles时,我得到了这个错误,如下所示: odata/Applications?$ expand =roles。
错误:执行命令定义时出错。有关详细信息,请参阅内部异常。“where子句”中的列“Project3.ApplicationId”未知
我知道这与映射有关,但我看不出是什么。
public class Role
{
public int Id { get; set; }
publ
我无法使用Automapper将ViewModel类映射为下面列出的类:
public class Product
{
[Key]
public int ProductId { get; set; }
public string Name { get; set; }
public ICollection<Color> Color { get; set; }
}
public class Color
{
[Key]
public int id { get; set; }
public string value { get; s
我正在尝试使用(POST/PUT)一个DTO对象,其中包含一个从JavaScript到ASP.NET核心(Web )的子对象集合,它的数据源是EF上下文。
主要的DTO类是这样的(当然,简化了):
public class CustomerDto {
public int Id { get;set }
...
public IList<PersonDto> SomePersons { get; set; }
...
}
我不知道的是如何将其映射到Customer类,这种方法不包含大量代码,只用于查找哪些人员已被添加/更新/删除等。
我使用过一些Aut
全。例如,我们有这样一个简单的类
public class SimpleModel
{
public int PropertyId { get; set; }
public ICollection<SimpleModelCollectionItem> SimpleCollection { get; set; }
}
public class SimpleModelCollectionItem
{
public int PropertyId { get; set; }
}
public class SimpleEntity
{
public in
这里需要点帮助。我有几个类,我试图使用Automapper映射。我用的是EF核心。基本域如下所示:
Public class A
{
public string Id {get; set;}
public string Name {get; set;}
public virtual Icollection<AB> AB {get; set;}
}
Public class B
{
public string Id {get; set;}
public string Name {get; set;}
public virtual ICollection
这是我的视图模型和数据模型
public class League{
ICollection<Player> Players{get;set;}
}
public class Player{
string name{get;set;}
}
public class LeagueViewModel{
ICollection<PlayerViewModel> Players{get;set;}
}
public class PlayerViewModel{
string name{get;set;}
}
这是我的地图简介
public
我在使用AutoMapper (这是一种优秀的技术)将业务对象映射到DTO时遇到了问题,在DTO中,我继承了集合中的抽象基类。
这是我的目标:
abstract class Payment
class CashPayment : Payment
class CreditCardPayment : Payment
我还有一个发票对象,它包含这样的付款集合:
public class Invoice
{
... properties...
public ICollection<Payment> Payments { get; set; }
我能否将新创建的对象设置为类的构造函数中提供的对象?
我想做这样的事:
public MyClass
{
public MyClass(MyClassDto myClassDto)
{
MyClass convertedMyClassObj = AutoMapper.LoadEntityFromDto<MyProject.DTO.MyClassDto, MyClass>(myClassDto);
//Assign the new object being created here equal to convertedMyClassObj:
this = convertedMyC
我有相关的文章和类别模型:
public class Article
{
...
public Category Category { get; set; }
}
public class Category
{
...
public ICollection<Article> Articles { get; set; }
}
这些是他们的ModelViews:
public class ArticleViewModel
{
...
public CategoryViewModel Category { get; set
我需要将存储过程的结果映射到一个复杂的对象:
假设我的存储过程返回A、B、C、D、E、F列
我有一堂课,说:
class ABC{
public int A;
public string B;
public int C;
public virtual ICollection<DEF> DEFObj;
}
DEF类别如下:
class DEF{
int value;
string comment;
}
因此,在这里,我需要将D,E,F列作为一个列表存储在ICollection<DEF>对象中。
哪个是最好的方法来完成这
我使用的是EF4.1POCO代码生成,它创建如下POCO实体:
public partial class Employee
{
public Employee()
{
this.Roles = new HashSet<Role>();
}
public System.Guid EmployeeGUID { get; set; }
public string EmployeeID { get; set; }
public string PIN { get; set; }
public string FullNa
我使用来映射我的域模型和DTO。当我映射Mapper.Map<SiteDTO, SiteEntity> 时,它可以很好地工作。
,但是当我使用相同实体的集合时,它不会映射.
Mapper.Map<Collection<SiteEntity>, Collection<SiteDTO>>(siteEntityCollection);
根据Automapper ,它说实现ICollection的列表将被映射,我使用的是实现ICollection的集合,但是automapper没有映射它。我是不是做错什么了。
public class Site
在实体框架中,我创建了一个Department类,它具有一个自动递增的DepartmentId和ICollection of Employees。
我不希望任何人在创建Department类的对象时看到这两个属性。有人能帮忙吗?
我试过使用访问修饰符,但没有起作用。
public class Department
{
public int DepartmentId { get; set; }
public string DepartmentName { get; set; }
public ICollection<Employee> Employees
我有一个LearningElement:
public class LearningElement
{
public int Id { get; set; }
}
还有一些学习元素:
public class Course : LearningElement
{
public string Content { get; set; }
}
public class Question: LearningElement
{
public string Statement { get; set; }
}
现在我有了一个可以有很多学习元素的结构:
public class Formatio
背景:我想在DTO映射到实体的时候加入业务规则。我认为将映射封装到扩展方法中是一种很好的方法。
IEntityDto是所有可以直接映射到实体的DTO实现的接口。
单个实例运行良好:
public static TEntity MapTo<TEntity>(this IEntityDto dto)
{
... Run Business Rules that don't require db access ...
return AutoMapper.Mapper.Map<TEntity>(dto);
}
我还想以同样的方式扩展ICollection:
我试图创建一个泛型方法来更新一个实体以及它从一个分离的对象中的所有集合属性。例如:
public class Parent{
public int Id { get; set; }
public string ParentProperty { get; set; }
public List<Child> Children1 { get; set; }
public List<Child> Children2 { get; set; }
}
public class Child{
public int Id { get; set;