我正在尝试将数据发布到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;
}
}
ZipCode 定义如下:
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"}
我注意到,如果我将version
andZipCodeType
字段(所有非引号字段)的引号用作"Version":"20"
and "ZipCodeType":"3"
,一切都很好,收到的实体是not null
.
请帮我解决这个问题。