mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-22 20:13:41 +08:00
UpdateCore
This commit is contained in:
@@ -34,7 +34,7 @@ namespace SqlSugar
|
||||
var pks = GetPrimaryKeys();
|
||||
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
||||
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||
var pkInfo = this.EntityInfo.Columns.Where(it=>it.IsIgnore==false).Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||
var pkValues = saveObjects.Select(it=>it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it,null));
|
||||
if(existsObjects==null)
|
||||
existsObjects=this.Context.Queryable<T>().In(pkValues).ToList();
|
||||
@@ -56,7 +56,7 @@ namespace SqlSugar
|
||||
var pks = GetPrimaryKeys();
|
||||
Check.Exception(pks.IsNullOrEmpty(), "Need primary key");
|
||||
Check.Exception(pks.Count() > 1, "Multiple primary keys are not supported");
|
||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||
var pkInfo = this.EntityInfo.Columns.Where(it => it.IsIgnore == false).Where(it => it.DbColumnName.Equals(pks.First(), StringComparison.CurrentCultureIgnoreCase)).First();
|
||||
var pkValues = saveObjects.Select(it => it.GetType().GetProperty(pkInfo.PropertyName).GetValue(it, null));
|
||||
if (existsObjects == null)
|
||||
existsObjects = this.Context.Queryable<T>().In(pkValues).ToList();
|
||||
|
@@ -24,6 +24,10 @@ namespace SqlSugar
|
||||
{
|
||||
return Context.Queryable<T>().InSingle(id);
|
||||
}
|
||||
public int Count<T>(Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).Count();
|
||||
}
|
||||
public List<T> GetList<T>() where T : class, new()
|
||||
{
|
||||
return Context.Queryable<T>().ToList();
|
||||
@@ -172,6 +176,7 @@ namespace SqlSugar
|
||||
{
|
||||
return Context.Queryable<T>().ToList();
|
||||
}
|
||||
|
||||
public List<T> GetList(Expression<Func<T, bool>> whereExpression)
|
||||
{
|
||||
return Context.Queryable<T>().Where(whereExpression).ToList();
|
||||
|
@@ -5,6 +5,7 @@ using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
namespace SqlSugar
|
||||
{
|
||||
@@ -835,7 +836,10 @@ namespace SqlSugar
|
||||
var newName = itemParameter.ParameterName + "_q_" + index;
|
||||
SugarParameter parameter = new SugarParameter(newName, itemParameter.Value);
|
||||
parameter.DbType = itemParameter.DbType;
|
||||
itemSql = itemSql.Replace(itemParameter.ParameterName, newName);
|
||||
itemSql = Regex.Replace(itemSql,string.Format(@"{0} ","\\"+itemParameter.ParameterName), newName+" ");
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\)", "\\" + itemParameter.ParameterName), newName+")");
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}\,", "\\" + itemParameter.ParameterName), newName+",");
|
||||
itemSql = Regex.Replace(itemSql, string.Format(@"{0}$", "\\" + itemParameter.ParameterName), newName);
|
||||
addParameters.Add(parameter);
|
||||
}
|
||||
parsmeters.AddRange(addParameters);
|
||||
|
Reference in New Issue
Block a user