Breezejs保存实体继承问题

时间:2015-03-02 22:02:42

标签: c# asp.net breeze

我正在为我的SPA使用breezejs和membershipreboot,我试图覆盖beforesaveentitiesdelegate以添加新客户。

我有一个客户类,它继承自membershipreboot'RelationalUserAccount',如下所示:

public class Customer : RelationalUserAccount
{
    public virtual string FirstName { get; private set; }
    public virtual string LastName { get; private set; }
}

我将以下代码用于'BeforeSaveEntitiesDelegate':

public Dictionary<Type, List<EntityInfo>> AddCustomer(Dictionary<Type, List<EntityInfo>> saveMap)
        {
                Dictionary<Type, List<EntityInfo>> newSaveMap = new Dictionary<Type, List<EntityInfo>>();

                var type = saveMap.FirstOrDefault();

                if (type.Key == typeof(Customer))
                {
                    EntityInfo entityInfo = type.Value.First();

                    List<EntityInfo> customers = new List<EntityInfo>();

                    if (entityInfo.EntityState == EntityState.Added)
                    {
                        Customer customertoCreate = entityInfo.Entity as Customer;}

                        newSaveMap.Add(typeof(Customer), customers);
                    }
                }
            }
            return newSaveMap;
        }

当我进入代码时,只填充了firstname和lastname字段,其他任何继承的字段都没有包含任何数据,'customer'实体的基本类型似乎是'customer' - 不应该是RelationalUserAccount base type is wrong

奇怪的是,在下面的代码中,savebundle似乎有正确的数据:

    public SaveResult CustomerAdd(JObject saveBundle)
    {
        CustomerBusinessLogic customerLogic = new CustomerBusinessLogic(mContextProvider);
        mContextProvider.BeforeSaveEntitiesDelegate = customerLogic.AddCustomer;
        return mContextProvider.SaveChanges(saveBundle);
    }

这是saveBundle的转储,因为您可以看到填充了用户名和电子邮件字段:

  "entities": [
    {
      "Key": -1,
      "FirstName": "asdf",
      "LastName": "asdf",
      "IsEmailVerified": false,
      "ID": "00000000-0000-0000-0000-000000000000",
      "Tenant": "3",
      "Username": "asdf@asdf.com",
      "Created": "1900-01-01T00:00:00Z",
      "LastUpdated": "1900-01-01T00:00:00Z",
      "IsAccountClosed": false,
      "AccountClosed": null,
      "IsLoginAllowed": false,
      "LastLogin": null,
      "LastFailedLogin": null,
      "FailedLoginCount": 0,
      "PasswordChanged": null,
      "RequiresPasswordReset": false,
      "Email": "asdf@asdf.com",
      "IsAccountVerified": false,
      "LastFailedPasswordReset": null,
      "FailedPasswordResetCount": 0,
      "MobileCode": null,
      "MobileCodeSent": null,
      "MobilePhoneNumber": null,
      "MobilePhoneNumberChanged": null,
      "AccountTwoFactorAuthMode": "0",
      "CurrentTwoFactorAuthStatus": "0",
      "VerificationKey": null,
      "VerificationPurpose": null,
      "VerificationKeySent": null,
      "VerificationStorage": null,
      "HashedPassword": null,
      "entityAspect": {
        "entityTypeName": "Customer:#Application.Domain.CustomerAggregate",
        "defaultResourceName": "Customers",
        "entityState": "Added",
        "originalValuesMap": {},
        "autoGeneratedKey": {
          "propertyName": "Key",
          "autoGeneratedKeyType": "Identity"
        }
      }
    }
  ],
  "saveOptions": {}
}

0 个答案:

没有答案