本文整理匯總了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;
}
}