我有一件事没有考虑过;在这些表上指定了一些关系。文档位于带有文件夹的一对多的许多方面,但它也与另一个名为OCR
的表的一对多关系的一侧。是否需要在我的Table
或Column
属性中捕获这些关系?非常感谢任何帮助。
我们正在尝试通过更改一列的值来更新表中的现有条目。我们的表格在代码部分(1)中指定。我通过代码部分(2)中指定的代码访问Document
表的实例,但这是我遇到异常的地方。
我。尝试将每个列(在文档和文件夹中)标记为UpdateCheck=UpdateCheck.Never
,以及使用CanBeNull
进行调整
II。尝试使用SubmitChanges
集上的ChangeConflict.Resolve(RefreshMode.KeepChanges)
和DataContext.Refresh(conflict, RefreshMode.KeepChanges)
调用第{2}部分myContext.ChangeConflicts
之后解决更改,然后重新执行SubmitChanges
III。尝试停用EntityRef<Folder>
Document
IV。尝试重新添加Document
表条目 - 这失败了,因为条目确实存在
诉轻轻地来回摇晃,尖叫着我自己嘶哑(这实际上有点帮助)
(1)
[Table(Name = "Document")]
public class Document
{
[Column(Name="Folder_ID", IsPrimaryKey = true)]
public int Folder_ID;
private EntityRef<Folder> folder;
[Association(Storage = "folder", ThisKey = "Folder_ID", OtherKey = "Folder_ID")]
public Folder Folder
{
get { return folder.Entity; }
set { folder.Entity = value; }
}
[Column]
public int Document_ID;
[Column(IsPrimaryKey = true)]
public int Image_ID;
[Column]
public string ImageName;
[Column]
public string ReasonForRejection;
}
[Table(Name = "Folder")]
public class Folder
{
[Column(Name = "Folder_ID", IsPrimaryKey = true)]
public int Folder_ID;
[Column(Name = "FolderName")]
public string FolderName;
}
(2)
public void MarkRejectReasonForImageID(int id, string rejReason, string dbPath)
{
// Create DataContext for MS Access '97 DB
DataContext myContext = new DataContext(new OleDBConnection(CreateJET4_OleDBConnectionString(dbPath));
// Add load options so that Folder entity is attached
DataLoadOptions loadOptions = new DataLoadOptions();
loadOptions.LoadWith<Document>(d => d.Folder);
myContext.LoadOptions = loadOptions;
// Make sure ObjectTracking is turned on
myContext.ObjectTrackingEnabled = true;
myContext.Connection.Open();
// Get Document from context matching input id
Document doc = myContext.GetTable<Document>().Where(d => d.Image_ID == id).ToList().FirstOrDefault();
if(doc!=null) {
// Mark matching reject reason on document
doc.ReasonForRejection = rejReason;
// Resubmit table changes
myContext.SubmitChanges(); // <-- "Runtime Exception: Row not found or changed."
}
myContext.Connection.Close();
}