WEB开发网
开发学院数据库MSSQL Server LINQ to SQL公共基类 阅读

LINQ to SQL公共基类

 2008-09-04 10:02:00 来源:WEB开发网   
核心提示: 删除方法是相似的,除了不需要调用Attach的第二个版本 (Attach(object entity, bool asModified)),LINQ to SQL公共基类(6),代码片断如下:public void Delete(TEntity entity, bool hasRelati

删除方法是相似的,除了不需要调用Attach的第二个版本 (Attach(object entity, bool asModified))。代码片断如下:

  public void Delete(TEntity entity, bool hasRelationship)
  {
  InitDataContext();
  try
  {
  if (hasRelationship)
  {
  //Remove the relationship between the entities;
  Detach(entity);
  }
  m_context.GetTable<TEntity>().Attach(entity);
  m_context.GetTable<TEntity>().DeleteOnSubmit(entity);
  m_context.SubmitChanges();
  }
  catch (ChangeConflictException)
  {
  m_context.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
  m_context.SubmitChanges();
  }
  }
  public void Delete(IList<TEntity> entities, bool hasRelationship)
  {
  InitDataContext();
  try
  {
  if (hasRelationship)
  {
  //Remove the relationship
  foreach (TEntity entity in entities)
  {
  Detach(entity);
  }
  }
  m_context.GetTable<TEntity>().AttachAll(entities);
  m_context.GetTable<TEntity>().DeleteAllOnSubmit(entities);
  m_context.SubmitChanges();
  }
  catch (ChangeConflictException)
  {
  m_context.ChangeConflicts.ResolveAll(RefreshMode.KeepCurrentValues);
  m_context.SubmitChanges();
  } 

上一页  1 2 3 4 5 6 7 8  下一页

Tags:LINQ to SQL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接