本文整理汇总了C#中UCsoft.Data.UCDbContext类的典型用法代码示例。如果您正苦于以下问题:C# UCDbContext类的具体用法?C# UCDbContext怎么用?C# UCDbContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UCDbContext类属于UCsoft.Data命名空间,在下文中一共展示了UCDbContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExistsViewEntity
/// <summary>
/// 是否存在该记录
/// </summary>
/// <returns></returns>
public bool ExistsViewEntity(Expression<Func<VCustomerContact , bool>> predicate)
{
using (UCDbContext db=new UCDbContext())
{
bool status= db.VCustomerContacts.Any(predicate);
return status;
}
}
示例2: ExistsViewEntity
/// <summary>
/// 是否存在该记录
/// </summary>
/// <returns></returns>
public bool ExistsViewEntity(Expression<Func<VSysDepartment , bool>> predicate)
{
using (UCDbContext db=new UCDbContext())
{
bool status= db.VSysDepartments.Any(predicate);
return status;
}
}
示例3: ExistsViewEntity
/// <summary>
/// 是否存在该记录
/// </summary>
/// <returns></returns>
public bool ExistsViewEntity(Expression<Func<VCompanyUser , bool>> predicate)
{
using (UCDbContext db=new UCDbContext())
{
bool status= db.VCompanyUsers.Any(predicate);
return status;
}
}
示例4: GetViewCount
/// <summary>
/// 获取数据总数
/// </summary>
/// <returns>返回所有数据总数</returns>
public int GetViewCount()
{
using (UCDbContext db=new UCDbContext())
{
var models= db.VCompanyUsers;
var sqlText = models.GetProperty("SqlText");
LogHelper.Debug(sqlText.ToString());
return models.Count();
}
}
示例5: GetViewEntity
/// <summary>
/// 获取指定的单个实体
/// 如果不存在则返回null
/// 如果存在多个则抛异常
/// </summary>
/// <param name="predicate">Lamda表达式</param>
/// <returns>Entity</returns>
public VCompanyUser GetViewEntity(Expression<Func<VCompanyUser, bool>> predicate)
{
using (UCDbContext db=new UCDbContext())
{
var model =db.VCompanyUsers.Where<VCompanyUser>(predicate);
var sqlText = model.GetProperty("SqlText");
LogHelper.Debug(sqlText.ToString());
return model.SingleOrDefault();
}
}
示例6: DeleteEntity
/// <summary>
/// 删除实体
/// </summary>
/// <param name="predicate">Lamda表达式</param>
public bool DeleteEntity(Expression<Func<TFunMyapp , bool>> predicate)
{
using (UCDbContext db=new UCDbContext())
{
TFunMyapp entity = db.TFunMyapps.Where(predicate).First();
int rows=db.TFunMyapps.Delete(entity);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
示例7: DeletesEntity
/// <summary>
/// 批量删除(实体集合)
/// </summary>
/// <param name="predicate">动态LINQ</param>
public bool DeletesEntity(List<string> predicates)
{
using (UCDbContext db=new UCDbContext())
{
if (db.Connection.State != ConnectionState.Open)
{
db.Connection.Open();
}
var tran = db.Connection.BeginTransaction();
try
{
foreach (var predicate in predicates)
{
var item = db.TFunMyapps.Where(predicate).FirstOrDefault();
if (null != item)
{
db.TFunMyapps.Delete(item);
}
}
tran.Commit();
LogHelper.Debug("批量删除成功!");
return true;
}
catch (Exception ex)
{
tran.Rollback();
LogHelper.Error("批量删除异常:", ex);
return false;
}
finally
{
if (db.Connection.State != ConnectionState.Closed)
{
db.Connection.Close();
}
}
}
}
示例8: GetList
/// <summary>
/// 获取所有的数据
/// </summary>
/// <param name="predicate">Lamda表达式</param>
/// <returns>返回所有数据列表</returns>
public List<TFunMyapp> GetList(Expression<Func<TFunMyapp, bool>> predicate)
{
using (UCDbContext db=new UCDbContext())
{
var models= db.TFunMyapps.Where<TFunMyapp>(predicate);
var sqlText = models.GetProperty("SqlText");
LogHelper.Debug(sqlText.ToString());
return models.ToList();
}
}
示例9: GetFields
/// <summary>
/// 根据条件查询某些字段(LINQ 动态查询)
/// </summary>
/// <param name="selector">要查询的字段(格式:new(ID,Name))</param>
/// <param name="predicate">筛选条件(id=0)</param>
/// <returns></returns>
public IQueryable<Object> GetFields(string selector, string predicate, params object[] values)
{
using (UCDbContext db=new UCDbContext())
{
var model = db.TFunMyapps.Where(predicate,values).Select(selector);
var sqlText = model.GetProperty("SqlText");
LogHelper.Debug(sqlText.ToString());
return (IQueryable<object>) model;
}
}
示例10: UpdateEntity
/// <summary>
/// 修改实体
/// </summary>
/// <param name="entity">实体对象</param>
public bool UpdateEntity(TSysDepartment entity)
{
using (UCDbContext db=new UCDbContext())
{
int rows= db.TSysDepartments.Update(entity);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
}
示例11: GetEntityWithExp
/// <summary>
/// 返回单个实体(带扩展字段)
/// </summary>
/// <param name="selector">要查询的字段</param>
/// <param name="expFields">存储扩展字段值的字段</param>
/// <param name="expSelector">要查询的扩展字段里面的字段</param>
/// <param name="predicate">查询条件</param>
/// <param name="values">参数</param>
/// <returns>Dictionary<String, Object>.</returns>
public Dictionary<string, object> GetEntityWithExp(string selector, string expFields, string expSelector,
string predicate,
params object[] values)
{
using (UCDbContext db=new UCDbContext())
{
IQueryable<object> model=null;
if (!String.IsNullOrEmpty(selector))
{
model =
((IQueryable<object>) db.TFunMyapps.Where(predicate, values).Select(selector, values));
}
else
{
model = ((IQueryable<object>)db.TFunMyapps.Where(predicate, values));
}
object temp = model.FirstOrDefault();
var sqlText = model.GetProperty("SqlText");
LogHelper.Debug("ELINQ Paging:<br/>" + sqlText.ToString());
Dictionary<string, object> result = new Dictionary<string, object>();
PropertyInfo[] propertyInfos = temp.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
var name = propertyInfo.Name; //输入的selector中的字段名
var value = propertyInfo.GetValue(temp, null); //输入的selector中的字段值
if (name == expFields)
{
IDictionary<string, JToken> cusFields =
(JObject) JsonConvert.DeserializeObject(value.ToString());
//循环添加新字段
foreach (var field in cusFields)
{
//只输出已选择的扩展字段(不输出直接留空)
if (!String.IsNullOrEmpty(expSelector))
{
object[] exps = Utils.StringToObjectArray(expSelector, ',');
var fieldKey = NamingConversion.Default.PropertyName(field.Key);
var fieldvalue = field.Value;
if (exps.Contains(fieldKey)) //只查询选择的扩展字段
{
result.Add(fieldKey, fieldvalue);
}
}
}
}
else
{
result.Add(name, value);
}
}
return result;
}
}
示例12: GetMaxId
/// <summary>
/// 获取最大Id(默认)
/// </summary>
/// <returns></returns>
public int GetMaxId()
{
using (UCDbContext db=new UCDbContext())
{
var models = db.TFunMyapps.Max(temp => temp.Id);
var sqlText = models.GetProperty("SqlText");
LogHelper.Debug(sqlText.ToString());
return models + 1;
}
}
示例13: UpdateEntityStatus
/// <summary>
/// 使用LINQ批量更改TClientInfo状态 2014-09-05 14:58:50 By 唐有炜
/// </summary>
/// <param name="fields">要更新的字段(支持批量更新)</param>
/// <param name="values">The values.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
public bool UpdateEntityStatus(List<Field> fields, params object[] values)
{
using (UCDbContext db=new UCDbContext())
{
if (db.Connection.State != ConnectionState.Open)
{
db.Connection.Open();
}
var tran = db.Connection.BeginTransaction();
try
{
foreach (var field in fields)
{
var entity = db.TFunMyapps.Where(field.Predicate, values).FirstOrDefault();
var propertyInfos = entity.GetType().GetProperties();
foreach (var p in propertyInfos)
{
if (p.Name == field.Key)
{
p.SetValue(entity, field.Value, null); //给对应属性赋值
}
}
db.TFunMyapps.Update(entity);
}
tran.Commit();
LogHelper.Debug("TFunMyapp字段批量更新成功。");
return true;
}
catch (Exception ex)
{
tran.Rollback();
LogHelper.Error("TFunMyapp字段批量更新异常:", ex);
return false;
}
finally
{
if (db.Connection.State != ConnectionState.Closed)
{
db.Connection.Close();
}
}
}
}
示例14: GetListWithExpByPage
/// <summary>
/// 查询分页(包括扩展字段) 2014-08-29 14:58:50 By 唐有炜
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页的数目</param>
/// <param name="selector">要查询的字段</param>
/// <param name="expFields">存储扩展字段值的字段</param>
/// <param name="expSelector">要查询的扩展字段里面的字段</param>
/// <param name="predicate">查询条件</param>
/// <param name="ordering">排序</param>
/// <param name="recordCount">记录结果数</param>
/// <param name="values">参数</param>
/// <returns>查询分页(包括扩展字段)</returns>
public List<Dictionary<string, object>> GetListWithExpByPage(int pageIndex, int pageSize, string selector,
string expFields, string expSelector,
string predicate, string ordering,
out int recordCount, params object[] values)
{
using (UCDbContext db=new UCDbContext())
{
//获取查询结果
//加上扩展字段值
var temps = db.TFunMyapps;
recordCount = temps.Count();
var prevCount = (pageIndex - 1)*pageSize;
IQueryable<object> models = null;
if (!String.IsNullOrEmpty(selector))
{
models = (IQueryable<object>) (temps
.Skip(prevCount)
.Take(pageSize)
.Where(predicate, values)
.Select(selector, values)
.OrderBy(ordering));
}
else
{
models = (IQueryable<object>)(temps
.Skip(prevCount)
.Take(pageSize)
.Where(predicate, values)
.OrderBy(ordering));
}
var sqlText = models.GetProperty("SqlText");
LogHelper.Debug("ELINQ Dynamic Paging:<br/>" + sqlText.ToString());
//转换为分页
var pages = models.ToPagination(pageIndex, pageSize, recordCount);
//组装输出
List<Dictionary<string, object>> results = new List<Dictionary<string, object>>();
foreach (var page in pages)
{
Dictionary<string, object> result = new Dictionary<string, object>();
PropertyInfo[] propertyInfos = page.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
var name = propertyInfo.Name; //输入的selector中的字段名
var value = propertyInfo.GetValue(page, null); //输入的selector中的字段值
if (name == expFields)
{
IDictionary<string, JToken> cusFields =
(JObject) JsonConvert.DeserializeObject(value.ToString());
//循环添加新字段
foreach (var field in cusFields)
{
//只输出已选择的扩展字段(不输出直接留空)
if (!String.IsNullOrEmpty(expSelector))
{
object[] exps = Utils.StringToObjectArray(expSelector, ',');
var fieldKey = NamingConversion.Default.PropertyName(field.Key);
var fieldvalue = field.Value;
if (exps.Contains(fieldKey)) //只查询选择的扩展字段
{
result.Add(fieldKey, fieldvalue);
}
}
}
}
else
{
result.Add(name, value);
}
}
results.Add(result);
}
return results;
}
}
示例15: GetListByPage
/// <summary>
/// 查询分页(可以自定义添加属性,不包括扩展字段) 2014-10-15 14:58:50 By 唐有炜
/// </summary>
/// <param name="pageIndex">页码</param>
/// <param name="pageSize">每页的数目</param>
/// <param name="selector">要查询的字段</param>
/// <param name="predicate">查询条件</param>
/// <param name="ordering">排序</param>
/// <param name="recordCount">记录结果数</param>
/// <param name="values">参数</param>
/// <returns>查询分页(不包括扩展字段)</returns>
public List<Dictionary<string, object>> GetListByPage(int pageIndex, int pageSize, string selector,string predicate, string ordering,
out int recordCount, params object[] values)
{
using (UCDbContext db=new UCDbContext())
{
//获取查询结果
//加上扩展字段值
var temps = db.TFunMyapps;
IQueryable<object> models = null;
if (!String.IsNullOrEmpty(selector))
{
models = (IQueryable<object>) (temps
.Where(predicate, values)
.Select(selector, values)
.OrderBy(ordering));
}
else
{
models = (IQueryable<object>)(temps
.Where(predicate, values)
.OrderBy(ordering));
}
var sqlText = models.GetProperty("SqlText");
LogHelper.Debug("ELINQ Dynamic Paging:<br/>" + sqlText.ToString());
//计算总数
recordCount = models.Count();
//转换为分页
var prevCount = (pageIndex - 1)*pageSize;
models=models.Skip(prevCount).Take(pageSize);
var pages = models.ToPagination(pageIndex, pageSize, recordCount);
//组装输出
List<Dictionary<string, object>> results = new List<Dictionary<string, object>>();
foreach (var page in pages)
{
Dictionary<string, object> result = new Dictionary<string, object>();
PropertyInfo[] propertyInfos = page.GetType().GetProperties();
foreach (var propertyInfo in propertyInfos)
{
var name = propertyInfo.Name; //输入的selector中的字段名
var value = propertyInfo.GetValue(page, null); //输入的selector中的字段值
result.Add(name, value);
}
results.Add(result);
}
return results;
}
}