public List<test_sub> GetTestSub(test_main testMain) { using (TestEntities context = new TestEntities()) { // 返回 子数据列表. return context.test_sub.Where(p => p.main_id == testMain.id).ToList(); } }
private void Fixuptest_main(test_main previousValue) { if (previousValue != null && previousValue.test_sub.Contains(this)) { previousValue.test_sub.Remove(this); } if (test_main != null) { if (!test_main.test_sub.Contains(this)) { test_main.test_sub.Add(this); } if (main_id != test_main.id) { main_id = test_main.id; } } else if (!_settingFK) { main_id = null; } }
public bool TestInsertMain(int id, string val) { // 请注意: // 由于是使用 WCF 来进行事务的管理. try { using (TestDataClassesDataContext context = new TestDataClassesDataContext()) { test_main mainData = new test_main() { id = id, value = val }; context.test_main.InsertOnSubmit(mainData); context.SubmitChanges(); } return true; } catch (Exception ex) { // 由于是使用 WCF 来管理事务. // 因此,发生异常了, 就必须抛出异常 // 不能自己 Catch 住了, 然后简单返回 false. // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。 throw new FaultException(ex.ToString(), new FaultCode(ex.Message)); } }
partial void Deletetest_main(test_main instance);
partial void Updatetest_main(test_main instance);
partial void Inserttest_main(test_main instance);
public bool TestInsertData(int main_id, string main_val, int sub_id, string sub_value) { // 请注意: // 由于是使用 WCF 来进行事务的管理. try { using (TestEntities context = new TestEntities()) { test_main mainData = new test_main() { id = main_id, value = main_val }; test_sub subData = new test_sub() { id = sub_id, main_id = main_id, value = sub_value }; context.AddTotest_main(mainData); context.AddTotest_sub(subData); context.SaveChanges(); } return true; } catch (Exception ex) { // 由于是使用 WCF 来管理事务. // 因此,发生异常了, 就必须抛出异常 // 不能自己 Catch 住了, 然后简单返回 false. // 如果自己 Catch 住了,简单返回 false 的话, WCF 认为你的程序执行正常,就你做的修改提交了,而不是回滚掉。 throw new FaultException(ex.ToString(), new FaultCode(ex.Message)); } }
/// <summary> /// 创建新的 test_main 对象。 /// </summary> /// <param name="id">id 属性的初始值。</param> public static test_main Createtest_main(global::System.Int32 id) { test_main test_main = new test_main(); test_main.id = id; return test_main; }
/// <summary> /// 用于向 test_main EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddTotest_main(test_main test_main) { base.AddObject("test_main", test_main); }