可以在服务器端进行编辑吗?
我有一个表,其中的值是以编程方式组成的,值一直在变化,所以我想要一个“更新”来重新计算表的值并提交更改。我不需要将任何数据传回客户端。
我在更改相关记录后尝试了该ObjectContext.SaveChanges()
方法DomainServiceClass
,但它不会更改数据库值。
我错过了什么?可能吗?
服务器端,DomainServiceClass 方法:
public IQueryable<POINT> UpdateDB()
{
var Points = ObjectContext.POINTS.Include("Readings").Include("Items").Include("LatestStatus");
List<POINT> itemsChanged = new List<POINT>();
foreach (Point point in Points)
{
int status = CalculateStatus(point)
if (point.LatestStatus.FirstOrDefault().Status != status)
point.LatestStatus.FirstOrDefault().Status = new status
}
ObjectContext.SaveChanges();
/*try
{
// Try to save changes, which may cause a conflict.
int num = ObjectContext.SaveChanges();
Console.WriteLine("No conflicts. " +
num.ToString() + " updates saved.");
}
catch (OptimisticConcurrencyException)
{
// Resolve the concurrency conflict by refreshing the
// object context before re-saving changes.
ObjectContext.Refresh(RefreshMode.ClientWins, inspectionPoints);
// Save changes.
ObjectContext.SaveChanges();
Console.WriteLine("OptimisticConcurrencyException "
+ "handled and changes saved");
}*/
return itemsChanged.AsQueryable();
}