/// <summary>
/// 用户数据交互
/// </summary>
public class User
{
private Entity.HappyOAEntities db = new Entity.HappyOAEntities();
/// <summary>
/// 注册新用户
/// </summary>
/// <param name="user"></param>
/// <param name="login"></param>
/// <returns></returns>
public int Add(Entity.User user, Entity.Login login)
{
//特殊需求,自定义事务
using (Entity.HappyOAEntities db2 = new Entity.HappyOAEntities())
{
db2.Connection.Open();
using (var tran = db2.Connection.BeginTransaction())
{
db2.Login.AddObject(login);
db2.SaveChanges();
user.ID = login.ID;
db2.User.AddObject(user);
db2.SaveChanges();
tran.Commit();
if (db2.Connection.State == System.Data.ConnectionState.Open)
db2.Connection.Close();
}
}
return login.ID;
}
}
/// 用户数据交互
/// </summary>
public class User
{
private Entity.HappyOAEntities db = new Entity.HappyOAEntities();
/// <summary>
/// 注册新用户
/// </summary>
/// <param name="user"></param>
/// <param name="login"></param>
/// <returns></returns>
public int Add(Entity.User user, Entity.Login login)
{
//特殊需求,自定义事务
using (Entity.HappyOAEntities db2 = new Entity.HappyOAEntities())
{
db2.Connection.Open();
using (var tran = db2.Connection.BeginTransaction())
{
db2.Login.AddObject(login);
db2.SaveChanges();
user.ID = login.ID;
db2.User.AddObject(user);
db2.SaveChanges();
tran.Commit();
if (db2.Connection.State == System.Data.ConnectionState.Open)
db2.Connection.Close();
}
}
return login.ID;
}
}