以下类是使用实体框架模型从模板自动生成的。是否需要将POCO类与实体框架一起使用6
namespace Entities
{
using System;
using System.Collections.Generic;
public partial class Country
{
public Country()
{
this.Regions = new HashSet<Region>();
}
public long CountryId { get; set; }
public string Code { get; set; }
public string Name { get; set; }
public bool Preferred { get; set; }
public System.DateTime LastChanged { get; set; }
public virtual ICollection<Region> Regions { get; set; }
}
}
我有一个只返回POX(Xml)和Json的Wcf Web服务。我想要返回自己的序列化对象,如;
public class MyResponseObject
{
public int RequestId {get;set;}
public List<Country> CountryList {get;set;}
//other properties
}
但我不想返回Regions ICollection。
的对象,然后可以使用类似
Newtonsoft.Json.JsonConvert.SerializeObject()
我是最好的我回自己的序列化的POCO对象以这种方式被退回?
所以基本上我会创建一个POCO类,我用来自实体对象的数据填充。为了填充POCO类对象,我最好只是遍历实体对象,为每次迭代填充POCO类?你可以给我一个例子请 – Tommassiov
@ Tommo1977有工具可以自动执行该过程,[AutoMapper](https://github.com/AutoMapper/AutoMapper)是一个受欢迎的工具。 –
@ Tommo1977您的web服务数据传输类不一定是POCO,如果它们涉及任何自定义继承,接口或属性。 Jus'说。 – Dai