I created a new LinqToSQL class and created an entity class in the editor with my hands, since autogeneration is not supported for Access DBMS.
In the code I create Context and in the designer I transfer OleDbConnection.
Everything is perfectly retrieved, but when you try to call SubmitChanges () to save changes, an error occurs:
An unhandled exception of type 'System.Data.Linq.ChangeConflictException' occurred in System.Data.Linq.dll
Additional information: Row not found or changed.
Tell me, what could be the joint?
Types mapped correctly, the primary key is present.
Code example:
using (DataClasses1DataContext db = new DataClasses1DataContext(connection)) { var t = db.TestTables.Where(x => x.TestTable_id >= 52121).ToList(); foreach (var val in t) { if (val.TestTable_id == 52121) { val.Path = "fff"; } } db.SubmitChanges(); } Entity Classes:
#pragma warning disable 1591 //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace Test { using System.Data.Linq; using System.Data.Linq.Mapping; using System.Data; using System.Collections.Generic; using System.Reflection; using System.Linq; using System.Linq.Expressions; using System.ComponentModel; using System; public partial class DataClasses1DataContext : System.Data.Linq.DataContext { private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource(); #region Extensibility Method Definitions partial void OnCreated(); partial void InsertTestTable(TestTable instance); partial void UpdateTestTable(TestTable instance); partial void DeleteTestTable(TestTable instance); #endregion public DataClasses1DataContext(string connection) : base(connection, mappingSource) { OnCreated(); } public DataClasses1DataContext(System.Data.IDbConnection connection) : base(connection, mappingSource) { OnCreated(); } public DataClasses1DataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource) { OnCreated(); } public DataClasses1DataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) : base(connection, mappingSource) { OnCreated(); } public System.Data.Linq.Table<TestTable> TestTables { get { return this.GetTable<TestTable>(); } } } [global::System.Data.Linq.Mapping.TableAttribute(Name="")] public partial class TestTable : INotifyPropertyChanging, INotifyPropertyChanged { private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty); private int _Image_id; private string _FaceImagePath; #region Extensibility Method Definitions partial void OnLoaded(); partial void OnValidate(System.Data.Linq.ChangeAction action); partial void OnCreated(); partial void OnTestTable_idChanging(int value); partial void OnTestTable_idChanged(); partial void OnPathChanging(string value); partial void OnPathChanged(); #endregion public TestTable() { OnCreated(); } [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Image_id", DbType="INT", IsPrimaryKey=true)] public int TestTable_id { get { return this._Image_id; } set { if ((this._Image_id != value)) { this.OnTestTable_idChanging(value); this.SendPropertyChanging(); this._Image_id = value; this.SendPropertyChanged("TestTable_id"); this.OnTestTable_idChanged(); } } } [global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FaceImagePath", DbType="VARCHAR(255)", CanBeNull=false)] public string Path { get { return this._FaceImagePath; } set { if ((this._FaceImagePath != value)) { this.OnPathChanging(value); this.SendPropertyChanging(); this._FaceImagePath = value; this.SendPropertyChanged("Path"); this.OnPathChanged(); } } } public event PropertyChangingEventHandler PropertyChanging; public event PropertyChangedEventHandler PropertyChanged; protected virtual void SendPropertyChanging() { if ((this.PropertyChanging != null)) { this.PropertyChanging(this, emptyChangingEventArgs); } } protected virtual void SendPropertyChanged(String propertyName) { if ((this.PropertyChanged != null)) { this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } } #pragma warning restore 1591 Table structure:
at System.Data.Linq.ChangeProcessor.SubmitChanges (ConflictMode failureMode) at System.Data.Linq.DataContext.SubmitChanges (ConflictMode failureMode) at Test.Program.Main (String [] args) in c: \ users \ iluxa \ documents \ visual studio 2015 \ Projects \ LINQToSQLTest \ Test \ Program.cs: line 30 at System.AppDomain._nExecuteAssembly (RuntimeAssembly assembly, String [] args) at System.AppDomain.ExecuteAssembly (String assemblyFile, Evidence assemblySecurity, String [] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly () at System.Threading.ExecutionContext.RunInternal (ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Re. Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run (ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart ()
