为什么更新没有保存在数据库中?

时间:2016-03-14 14:00:18

标签: c# entity-framework-6

我有以下代码来保存数据库中的数据:

Traceback (most recent call last):
  File "chainer/examples/mnist/train_mnist.py", line 10, in <module>
    import numpy as np
  File "/usr/local/lib/python2.7/site-packages/numpy/__init__.py", line 180, in <module>
    from . import add_newdocs
  File "/usr/local/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in <module>
    from numpy.lib import add_newdoc
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/__init__.py", line 8, in <module>
    from .type_check import *
  File "/usr/local/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in <module>
    import numpy.core.numeric as _nx
  File "/usr/local/lib/python2.7/site-packages/numpy/core/__init__.py", line 58, in <module>
    from numpy.testing import Tester
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/__init__.py", line 14, in <module>
    from .utils import *
  File "/usr/local/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in <module>
    from tempfile import mkdtemp
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
    import io as _io
  File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/io.py", line 51, in <module>
    import _io
ImportError: dlopen(/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so, 2): Symbol not found: __PyCodecInfo_GetIncrementalDecoder
  Referenced from: /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so
  Expected in: flat namespace
 in /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so

但是,SQL Server中的表未更新。请帮忙。

2 个答案:

答案 0 :(得分:0)

在调用保存更改之前,请查看更改跟踪器以查看已添加/删除/修改的内容。您不得添加/删除/修改任何内容。

context.ChangeTracker.Entries().Where(e => e.State == EntityState.Added);
context.ChangeTracker.Entries().Where(e => e.State == EntityState.Deleted);
context.ChangeTracker.Entries().Where(e => e.State == EntityState.Modified);

答案 1 :(得分:-1)

为什么不直接保存您引用的客户,而不是再次从数据库加载客户,然后修改值。

public void SaveCustomer(customer_table customer)
{
    if (customer.customerID == 0)
    {
        context.customer_table.Add(customer);
    }
    else
    {            
        context.customer_table.AddOrUpdate(customer);
    }
    context.SaveChanges();
}