不能发布给EntitySetController,接收到的实体为null

问题描述 投票:0回答:1

我试图发布数据EntitySetController,但它是由控制器接收实体总是null

OData配置为:

public static class ODataApiConfig
        {
            public static void Register(HttpConfiguration config)
            {
                config.Routes.MapODataRoute("DefaultOdata" , "odata" , GetImplicitModel());
            }

        public static IEdmModel GetImplicitModel()
        {
            var builder = new ODataConventionModelBuilder();
            builder.EntitySet<ZipCode>("ZipCodes");        

            return builder.GetEdmModel();
        }
    }

我有以下控制器:

public class ZipCodesController : EntitySetController<ZipCode, String>
    {
         public IUnitOfWork Iuow { get; set; }

         public ZipCodesController(IUnitOfWork unitOfWork)
         {
             Iuow = unitOfWork;
         }

         [Queryable]
         public override IQueryable<ZipCode> Get()
         {
             return Iuow.GetStandardRepository<ZipCode>().GetAll();
         }

         protected override string GetKey(ZipCode entity)
         {
             return entity.Id.ToString();
         }
         protected override ZipCode GetEntityByKey(string key)
         {
             return Iuow.GetStandardRepository<ZipCode>().GetById(key);
         }

         protected override ZipCode CreateEntity(ZipCode entity)
         {
             Iuow.GetStandardRepository<ZipCode>().Add(entity);
             Iuow.Commit();
             return entity;
         }
    }

的邮编被定义为这样:

 public class ZipCode
        {
            public Guid Id { get; set; }
            public long Version { get; set; }
            public String CreatedBy { get; set; }
            public String LastModifiedBy { get; set; }
            public String ZipPostalCode{ get; set; }
            public ZipCodeType ZipCodeType { get; set; }
            public Guid CountryId { get; set; }
            public Guid CountyId { get; set; }
            public Guid StateId { get; set; }
            public Guid CityId { get; set; }
            public String Latitude { get; set; }
            public String Longitude { get; set; }

        }

我试图通过Fiddler张贴下面的实体,但是接收实体总是null

{"Id":"6b146d72-2681-4d47-8cc4-75e64e2dea66", "Version":20, "CreatedBy":"ae5882fb-b833-46d7-9f58-0505ec2a6f8f","LastModifiedBy":"ae5882fb-b833-46d7-9f58-0505ec2a6f8f","ZipPostalCode":"92020","ZipCodeType": 3,"CountryId":"6a54b9be-8726-4376-a99e-989884e2b724","CountyId":"9c4052fa-49f2-4e5e-995f-317abd16814b","StateId":"0da54905-6acd-4886-a9d1-f3e6d9eb7c60","CityId":"ba543bc1-7eb7-4e14-bbea-2ffcac5b2e2c","Latitude":"36.978256","Longitude":"-121.952464"}

我注意到,如果我用versionZipCodeType领域(所有非引用域)作为"Version":"20""ZipCodeType":"3"引号,一切都很好,并获得实体not null

请帮我解决这个问题。

asp.net post asp.net-web-api odata complextype
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.