2016-11-11 57 views
1

我在写一个WCF服务,它向前端公开一个列表。这将是这样的:更改WCF列表中实体的名称

public List<customers> getCustomers() 
{ 
    //code goes here like DB operations 
} 

这里的客户列表包含下列文件

int Id{set;get;} 

int CustomerName{set;get;} 

int CustomerPlace{set;get;} 

在这里,在这个名单我旺旺ID被显示为客户ID。我无法更改字段的名称,因为我正在使用一些数据库自动制作器。那么有什么东西可以将Id更改为客户ID吗?

请帮我解决这个问题。

在此先感谢

+0

我的意思是我想ID更改为客户ID虽然我们暴露给Service.I希望显示引用属性是查看目的。 – user2452752

+0

看起来您正在服务中共享模型(您从数据库映射的类),但这并不好。您可以使用'CustomerId'创建一个服务模型,并在您的服务中使用此模型。服务可以有自己的模式,为客户服务。 –

回答

2

仅用于显示目的意味着创建自定义模型筛选

[DataContract] 
    public class Customers 
    {  
    [DataMember] 
    [Display(Name = "CustomerId")] 
    public int Id{set;get;} 

    [DataMember] 
    public int CustomerName{set;get;} 

    [DataMember] 
    public int CustomerPlace{set;get;} 
    } 


    [MetadataType(typeof(Customers))] 
    public partial class customers 
    { } 

,并使用List这样public List<Customers> getCustomers()