I have silverlight application. This is an invoke operation (in Open Ria Service - WCF Ria Service open source version) with Entity Framework 6.
public List<VaultAmount> GetCurrentVaultAmounts(Guid vaultId)
{
return this.DbContext.VaultAmounts
.Include(v => v.VaultAmountQuantities)
.Include(v => v.VaultCurrency)
.Include(v => v.Vault)
.Include(v => v.VaultAmountQuantities.Select(vaq => vaq.VaultCurrency))
.Where(v => v.VaultId == vaultId && v.IsCurrent).ToList();
}
[Invoke]
public void UpdateVaultRemainders(List<VaultAmountQuantity> updatedQuantities, string comment, Guid userId,
string friendlyName,
Guid vaultAmountId, int currencyId)
{
VaultAmount vaultAmount =
this.DbContext.VaultAmounts
.Include("Vault")
.SingleOrDefault(va => va.VaultAmountId == vaultAmountId);
if (vaultAmount == null && vaultAmount.Vault == null) return;
//Get FromVault and ToVault with amounts and updatedQuantities
List<VaultAmount> currentAmounts = GetCurrentVaultAmounts(vaultAmount.Vault.VaultId);
//Vault vault = GetVaultWithCurrentAmountsAndQuantitiesById(vaultAmount.Vault.VaultId);
var helper = new RemainderVAHelper(currentAmounts, userId, friendlyName, currencyId, updatedQuantities,
comment,
BS2VaultEventTypes.Correction);
//................................
foreach (var amount in currentAmounts)
{
if (amount.IsCurrent == false)
{
DbEntityEntry<VaultAmount> entityEntry = this.DbContext.Entry(amount);
entityEntry.State = EntityState.Modified;
}
}
this.DbContext.SaveChanges();
}
In RemainderVAHelper class I am changing currentAmounts objects, set IsCurrent property to false. But currentAmounts objects entityEntry.State are still Unchanged . Why? Yes, I can set their states as Modified (as I am doing in method), but I think it is not very good thing. Can you tell me why my objects state doesn't changes to Modified ?
如果您不使用更改跟踪代理,则在调用DetectChanges或调用SaveChanges(调用DetectChanges)之前,EF无法知道您是否修改了属性。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.