我有 3 个项目的 ac# 解决方案:
- 模型(EF POCO 类)
- WCF 服务
- 客户端(主应用程序)
在项目模型下,我有一个模型Employee:
[Table("employee")]
public class Employee
{
[Key, Column("organizationid", TypeName = "uniqueidentifier", Order=0)]
public Guid OrganizationId { get; set; }
[Key, Column("personid", TypeName = "uniqueidentifier", Order=1)]
public Guid PersonId { get; set; }
[Column("jobtitle", TypeName = "nvarchar")]
public String JobTitle { get; set; }
[Column("active", TypeName = "bit")]
public Boolean Active { get; set; }
[Column("telecom", TypeName = "nvarchar")]
public String Telecom { get; set; }
[Column("email", TypeName = "nvarchar")]
public String Email { get; set; }
[Column("confidentialitycode", TypeName = "nvarchar")]
public String ConfidentialityCode { get; set; }
[Column("priority", TypeName = "int")]
public Int32 Priority { get; set; }
#region Foreign Relations
[ForeignKey("OrganizationId")]
public virtual Organization CurrentOrganization { get; set; }
[ForeignKey("PersonId")]
public virtual Person CurrentPerson { get; set; }
#endregion
}
然后我创建了一个名为Test.svc的 WCF 服务,它具有以下内容:
public class Test : ITest
{
public Model.POCO.Employee DoWork()
{
Model.POCO.Employee newItem = new Model.POCO.Employee();
newItem.PersonId = Guid.NewGuid();
newItem.OrganizationId = Guid.NewGuid();
newItem.Priority = 1;
newItem.Telecom = "";
newItem.JobTitle = "";
newItem.Email = "";
newItem.Active = true;
return newItem;
}
}
[ServiceContract]
public interface ITest
{
[OperationContract]
Model.POCO.Employee DoWork();
}
在客户端项目中,我添加了一个按钮,在单击事件中,我有以下代码:
private void button1_Click(object sender, EventArgs e)
{
DataReference.WCFTest.TestClient svc = new DataReference.WCFTest.TestClient();
var employee = svc.DoWork();
svc = null;
}
如果我查看“var employee”,我可以看到该对象在那里并且运行良好,但“employee”不是Model.POCO.Employee类型,而是WCFTest.Employee类型。
如何让我的 WCF 服务返回 Model.POCO.Employee?有什么解决方法吗?或者我可以将 WCFTest.Employee 自动包装到 Model.POCO.Employee 吗?
非常感谢。