0

我正在使用以下代码在客户端使用 FullName 扩展我的服务上下文:

public partial class Customer {
    public string FullName
    {
        get
        {
            return string.Concat(LastName, (FirstName == "" ? "" : ", "), FirstName);
        }
    }
}

这很好,直到我需要使用 AddOBject 方法将新对象添加到上下文中。它抛出一个异常。当我删除 FullName 扩展时,AddObject 方法将新对象保存到数据库中。扩展我的上下文并使其仍可更新和可插入的最佳方法是什么?

编辑: DataServiceRequest 异常:

System.Data.Services.Client.DataServiceRequestException was not handled by user code.
  HResult=-2146233079
  Message=Fehler beim Verarbeiten dieser Anforderung.
  Source=Microsoft.Data.Services.Client.WindowsStore
  StackTrace:
       at System.Data.Services.Client.SaveResult.HandleResponse()
       at System.Data.Services.Client.BaseSaveResult.EndRequest()
       at System.Data.Services.Client.DataServiceContext.EndSaveChanges(IAsyncResult asyncResult)
       at Pointsale.Client.Service.PointsaleEntities.<SaveChanges>b__0(IAsyncResult asResult) in c:\Users\Jan\Desktop\pointsale_worksapce\pointsale.client\Helper\TenantHelper.cs:line 98
       at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
  InnerException: System.Data.Services.Client.DataServiceClientException
       HResult=-2146233079
       Message=<?xml version="1.0" encoding="utf-8"?><m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"><m:code /><m:message xml:lang="de-DE">Error occurred while processing this request.</m:message></m:error>
       StatusCode=400
       InnerException: 

SaveChanges 方法覆盖以使其异步:

public async Task<DataServiceResponse> SaveChanges()
{
    var queryTask = Task.Factory.FromAsync(this.BeginSaveChanges(null, null), asResult =>
    {

        var result = this.EndSaveChanges(asResult);
        return result;

    });
    return await queryTask;
}

在 EndSaveChanges 发生错误。

4

0 回答 0