Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Where 方法 使用like 的奇怪现象 #1790

Open
ckbabby opened this issue Apr 21, 2024 · 1 comment
Open

Where 方法 使用like 的奇怪现象 #1790

ckbabby opened this issue Apr 21, 2024 · 1 comment

Comments

@ckbabby
Copy link

ckbabby commented Apr 21, 2024

问题描述及重现代码:

using FreeSql;
using FreeSql.DataAnnotations;

using (var fsql = new FreeSqlBuilder()
	.UseConnectionString(DataType.Sqlite, "data source=111.db")
	.UseAutoSyncStructure(true)
	.UseNoneCommandParameter(true)
	.UseMonitorCommand(cmd => Console.WriteLine(cmd.CommandText + "\r\n"))
	.Build())
{
    var table = fsql.CodeFirst.DynamicEntity("user", new TableAttribute { Name = "t_user" })
      .Property("id", typeof(int), new ColumnAttribute { IsIdentity = true, IsPrimary = true })
      .Property("username", typeof(string), new ColumnAttribute { StringLength = 32 })
       .Property("adminIds", typeof(string), new ColumnAttribute { StringLength = -1 })
      .Build();

    //如果有必要,请将 table 缓存起来
    if (fsql.DbFirst.ExistsTable(table.DbName) == false)
        fsql.CodeFirst.SyncStructure(table.Type); //创建表

    var dict = new Dictionary<string, object>();
    dict["username"] = "aaa";
    dict["adminIds"] = ",1,2,3,4,5";
    object obj = table.CreateInstance(dict);
    var insNum = fsql.Insert<object>().AsType(table.Type).AppendData(obj).ExecuteAffrows();
    ///这里输出的sql语句替换参数化的地方是能查询出来的,但是代码返回结果为空数组
    var list = fsql.Select<object>().AsType(table.Type).Where("adminIds like '%,@a,%'", new { a = 1 }).ToList();
    Console.ReadLine();
}

数据库版本

Sqlite

安装的Nuget包

FreeSql.All 3.2.821

.net framework/. net core? 及具体版本

@ckbabby ckbabby changed the title Where 方法阐述会使用like 的奇怪现象 Where 方法 使用like 的奇怪现象 Apr 21, 2024
@2881099
Copy link
Collaborator

2881099 commented Apr 21, 2024

adminIds like @p1

要这样写,你写的被当成了字符串

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants