public static bool insertDataToTable1(int numberID, string text) { bool response = false; try { using (var ctx = new MyTestDV()) { ctx.TestTable1.Add( new TestTable1() { ID = numberID, Text = text }); ctx.SaveChanges(); response = true; } } catch (Exception) { response = false; } return response; }
public static bool insertDataToTable1(SqlConnection connection, System.Data.SqlClient.SqlTransaction transaction, int numberID, string text) { bool response = false; MetadataWorkspace workspace = new MetadataWorkspace ( new string[] { string.Format("res://{0}/MyTestDB.csdl" , "*"), string.Format("res://{0}/MyTestDB.ssdl" , "*"), string.Format("res://{0}/MyTestDB.msl" , "*") }, new Assembly[] { Assembly.GetAssembly(typeof (jfso.demos.SqlTransaction.DAL.MyTestDV)) } ); EntityConnection _conn = new EntityConnection(workspace, connection); try { using (var ctx = new MyTestDV(_conn, false)) { ctx.Database.UseTransaction(transaction); ctx.TestTable1.Add( new TestTable1() { ID = numberID, Text = text }); ctx.SaveChanges(); response = true; } } catch (Exception) { response = false; } return response; }