old_flsystem/类库/Api.Framework/Easy4/Context/SessionFactory.cs

49 lines
1.1 KiB
C#
Raw Permalink Normal View History

2022-09-20 03:10:29 +00:00
using System;
using System.Linq;
namespace Easy4net.Context
{
/// <summary>
/// 持久层对象获取帮助
/// </summary>
public class SessionFactory
{
/// <summary>
/// 根据数据库类型名获取对应的持久层对象
/// </summary>
/// <param name="connName"></param>
/// <returns></returns>
public static Session GetSession(ConnectionConfig config)
{
Session session = SessionThreadLocal.Get();
if (session == null)
{
session = Session.NewInstance(config);
SessionThreadLocal.Set(session);
}
else
{
session.ConnectDB(config);
}
return session;
}
/// <summary>
/// 获取MSSQL持久层对象
/// </summary>
/// <returns></returns>
public static Session GetSession()
{
Session session = SessionThreadLocal.Get();
if (session == null)
{
session = Session.NewInstance(null);
SessionThreadLocal.Set(session);
}
return session;
}
}
}