This commit is contained in:
sunkaixuan 2025-04-07 18:57:59 +08:00
parent 6f50ac1b95
commit 05f3209812
4 changed files with 48 additions and 5 deletions

View File

@ -8,6 +8,7 @@ namespace OrmTest
{
static void Main(string[] args)
{
UnitStringToExp.Init();
//Each example will automatically create a table and can run independently.
//每个例子都会自动建表 并且可以独立运行
_1_CodeFirst.Init();

View File

@ -56,6 +56,15 @@ namespace OrmTest
" it.Name as Name" }
, 10)
.ToListAsync().GetAwaiter().GetResult();
var userInfo5 = db.Queryable<Order>()
.Select("it",
new List<string>()
{ "it.Id as userId",
" {0} as id",
" it.Name as Name" }
, 10)
.InSingleAsync(1).GetAwaiter().GetResult();
}
private static void Test03()

View File

@ -11,7 +11,7 @@ namespace SqlSugar
internal object MethodInfos { get; set; }
internal SqlSugarProvider Context { get; set; }
public DeleteNavMethodInfo IncludeByNameString(string navMemberName, DeleteNavOptions updateNavOptions = null)
public DeleteNavMethodInfo IncludeByNameString(string navMemberName, DeleteNavOptions deleteNavOptions = null)
{
var type = MethodInfos.GetType().GetGenericArguments()[0];
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
@ -20,11 +20,11 @@ namespace SqlSugar
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
var method = this.MethodInfos.GetType().GetMyMethod("Include", 2, isList)
.MakeGenericMethod(properyItemType);
var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
var obj = method.Invoke(this.MethodInfos, new object[] { exp, deleteNavOptions });
this.MethodInfos = obj;
return this;
}
public DeleteNavMethodInfo ThenIncludeByNameString(string navMemberName, DeleteNavOptions updateNavOptions = null)
public DeleteNavMethodInfo ThenIncludeByNameString(string navMemberName, DeleteNavOptions deleteNavOptions = null)
{
var type = MethodInfos.GetType().GetGenericArguments()[1];
var entityInfo = this.Context.EntityMaintenance.GetEntityInfo(type);
@ -33,7 +33,7 @@ namespace SqlSugar
Expression exp = UtilMethods.GetIncludeExpression(navMemberName, entityInfo, out properyItemType, out isList);
var method = this.MethodInfos.GetType().GetMyMethod("ThenInclude", 2, isList)
.MakeGenericMethod(properyItemType);
var obj = method.Invoke(this.MethodInfos, new object[] { exp, updateNavOptions });
var obj = method.Invoke(this.MethodInfos, new object[] { exp, deleteNavOptions });
this.MethodInfos = obj;
return this;
}

View File

@ -10,6 +10,39 @@ namespace SqlSugar
public class DynamicCoreSelectModel
{
public object Value { get; set; }
public object InSingle(object value)
{
if (Value is null)
{
throw new InvalidOperationException("Value cannot be null.");
}
var method = Value.GetType().GetMyMethod("InSingle", 1);
if (method == null)
{
throw new InvalidOperationException("The Value object does not have an InSingle method with one parameter.");
}
return method.Invoke(Value, new object[] { value });
}
public async Task<object> InSingleAsync(object value)
{
if (Value is null)
{
throw new InvalidOperationException("Value cannot be null.");
}
var method = Value.GetType().GetMyMethod("InSingleAsync", 1);
if (method == null)
{
throw new InvalidOperationException("The Value object does not have an InSingleAsync method with one parameter.");
}
var task = (Task)method.Invoke(Value, new object[] { value });
return await GetTask(task).ConfigureAwait(false);
}
public object ToList()
{