0
我試圖將新添加的實體作爲批量請求發佈到我的odata v3 web api使用微風,但應該傳遞給我的odata post方法的實體始終爲空。批處理請求實體始終爲空
我的批次路由配置:
config.Routes.MapODataServiceRoute(
routeName: "odata",
routePrefix: "odata",
model: builder.GetEdmModel(),
batchHandler: new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer)
);
我的控制器交方法,該方法是具有空entitiy recieving呼叫:
public IHttpActionResult Post([FromBody]ApiUserEntity apiUserEntity)
{
if (apiUserEntity == null)
return BadRequest(ModelState);
}
實體:
public class BaseEntity
{
public int Id { get; set; }
public DateTime CreatedAt { get; set; }
}
public class ApiUserEntity : BaseEntity
{
public string Username { get; set; }
public string Password { get; set; }
public string Email { get; set; }
public string Salt { get; set; }
public ApiUserRole Role { get; set; }
public ApiPermission Permission { get; set; }
}
enum ApiUserRole {
Admin,
Staff,
User
}
enum ApiPermission {
Read,
Write,
ReadWrite
}
簡化的代碼我如何通過微風撥打savechanges
manager.createEntity('ApiUserEntity',
{
Id: 1,
Username: "user",
Password: "password",
Email: "Email",
Salt: "Salt",
Role: "1",
Permission: "1"
});
manager.saveChanges();
當我檢查與小提琴手請求我看到它發送正確的數據我加入breezejs:
POST http://localhost:22594/odata/$batch HTTP/1.1
Host: localhost:22594
Connection: keep-alive
Content-Length: 640
Pragma: no-cache
Cache-Control: no-cache
MaxDataServiceVersion: 3.0
Origin: http://localhost:51406
User-Agent: Mozilla/ 5.0 (Windows NT 6.3; WOW64) AppleWebKit/ 537.36(KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36
Content-Type: multipart/mixed; boundary = batch_fffa - 6088 - 92e7
Accept: multipart/mixed
DataServiceVersion: 2.0
Referer: http://localhost:51406/
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en; q=0.8,nl; q=0.6,nb; q=0.4,es; q = 0.2
--batch_fffa - 6088 - 92e7
Content-Type: multipart/mixed; boundary = changeset_d571 - 5fc6 - 6f89
--changeset_d571 - 5fc6 - 6f89
Content-Type: application/http
Content - Transfer-Encoding: binary
POST ApiUsers HTTP/1.1
Content-ID: 1
DataServiceVersion: 2.0
Accept: application/atomsvc + xml; q = 0.8, application/json; odata = fullmetadata; q = 0.7, application/json; q = 0.5, */*;q=0.1
Content-Type: application/json
MaxDataServiceVersion: 3.0
{"Username":"name","Password":"password","Email":"email","Salt":"dasdasdasd","Role":"1","Permission":"1","Id":1,"CreatedAt":"1899-12-31T23:00:00"}
--changeset_d571-5fc6-6f89--
--batch_fffa-6088-92e7--
和控制器上的POST方法時,我調試正在熱播,但該實體始終爲空。我正在使用實體框架,並使用conventionmodelbuilder在webapi上生成元數據。
向我們展示breezejs代碼和實體? – 2014-12-08 07:35:09
用我的實體和微風代碼更新了問題,謝謝。 – 2014-12-08 11:56:22
什麼是ApiUserRole和ApiPermission?他們看起來很類,但是你將它們用作整數值。 – 2014-12-08 11:58:26