JSON响应中的ODATA WebAPI更改列名称

时间:2019-03-15 05:19:22

标签: json odata

我正在使用Microsoft.Data.OData,并且在访问控制器上的方法时工作正常。我希望[SupplierID]列以[SupplierCode]的形式在JSON对象中返回。

任何帮助将不胜感激。

谢谢

Neeraj Matta

下面是代码:

供应商

命名空间WebApplication9

{
using System;
using System.Collections.Generic;

public partial class Supplier
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
    public Supplier()
    {
        this.Invoices = new HashSet<Invoice>();
        this.SupplierBankInfoes = new HashSet<SupplierBankInfo>();
    }

    public string SupplierID { get; set; }
    public string SupplierName { get; set; }
    public string Status { get; set; }
    public Nullable<bool> POREQ { get; set; }

    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<Invoice> Invoices { get; set; }
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
    public virtual ICollection<SupplierBankInfo> SupplierBankInfoes { get; set; }
}

}

SupplierController

    public class SuppliersController : ODataController
{
    private ABBYYEntities db = new ABBYYEntities();

    // GET: odata/Suppliers
    [EnableQuery]
    public IQueryable<Supplier> GetSuppliers()
    {
        return db.Suppliers;
    }

}

0 个答案:

没有答案