csharp Get Getall使用Odata + devexpress进行CRUD操作
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Get Getall使用Odata + devexpress进行CRUD操作相关的知识,希望对你有一定的参考价值。
[HttpGet]
public HttpResponseMessage Get(DataSourceLoadOptions loadOptions)
{
var model = _db.GetTrKartContext.Worker.Where(x => x.Status == 1).ToList().Select(x => new { x.WorkerID, x.Name });
return Request.CreateResponse(DataSourceLoader.Load(model, loadOptions));
}
[HttpPost]
public HttpResponseMessage Post(FormDataCollection form)
{
var values = form.Get("values");
var _testTable = new ProCard.OdataServices.Models.Worker();
JsonConvert.PopulateObject(values, _testTable);
_testTable.RegistrationDate = DateTime.Now;
_db.GetTrKartContext.AddToWorker(_testTable);
_db.GetTrKartContext.SaveChanges();
return Request.CreateResponse(HttpStatusCode.Created);
}
[HttpPut]
public HttpResponseMessage Put(FormDataCollection form)
{
var key = Convert.ToInt64(form.Get("key"));
var profession = Convert.ToInt64(form.Get("key"));
var values = form.Get("values");
//profession field is not included, you need to add it to your values _testTab;e
var _testTable = _db.GetTrKartContext.Worker.AsEnumerable().Where(e => e.WorkerID == key).FirstOrDefault();
JsonConvert.PopulateObject(values, _testTable);
if (_testTable != null)
{
_db.GetTrKartContext.UpdateObject(_testTable);
_db.GetTrKartContext.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK);
}
return Request.CreateResponse(HttpStatusCode.NotFound);
}
[HttpDelete]
public HttpResponseMessage Delete(FormDataCollection form)
{
var key = Convert.ToInt64(form.Get("key"));
var _testTable = _db.GetTrKartContext.Worker.AsEnumerable().Where(e => e.WorkerID == key).FirstOrDefault();
if (_testTable != null)
{
_testTable.Status = 0;
_db.GetTrKartContext.UpdateObject(_testTable);
_db.GetTrKartContext.SaveChanges();
return Request.CreateResponse(HttpStatusCode.OK);
}
return Request.CreateResponse(HttpStatusCode.NotFound);
}
以上是关于csharp Get Getall使用Odata + devexpress进行CRUD操作的主要内容,如果未能解决你的问题,请参考以下文章
二级缓存如何与 getAll 一起使用并进入 gorm?
如何正确地将 OData 与 ASP.net Core 集成
带有“和”运算符的OData过滤器无法在Web Api中运行
System.Web.Http 中的 OData SingleResult 不明确
.Net Core 1.1 上的 OData v4 缺少 /$metadata
WebAPI OData $format 到 xml