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

插入字典失败 #1601

Closed
wangboshun opened this issue Aug 24, 2023 · 9 comments
Closed

插入字典失败 #1601

wangboshun opened this issue Aug 24, 2023 · 9 comments

Comments

@wangboshun
Copy link
Contributor

问题描述及重现代码:

// c# code

var dict=new  List<Dictionary<string, object>>();
Dictionary<string, object> d=new Dictionary<string, object>();
d.Add("id",1);
d.Add("name","name1");
dict.Add(d);


表包含两个字段id和name,其中id为主键
fsql.InsertOrUpdateDict(dict).AsTable("table").WherePrimary("id").IfExistsDoNothing().ExecuteAffrows();


异常信息System.NullReferenceException: Object reference not set to an instance of an object.
   at FreeSql.Internal.CommonProvider.Select0Provider`2.AsType(Type entityType)
   at FreeSql.MySql.Curd.MySqlInsertOrUpdate`1.<>c__DisplayClass1_0.<ToSql>b__3(Object rowd, Int32 idx, StringBuilder sb)
   at FreeSql.Internal.CommonProvider.InsertProvider`1.ToSqlValuesOrSelectUnionAllExtension103(Boolean isValues, Action`3 onrowPre, Action`3 onrow, Boolean isAsTableSplited)
   at FreeSql.Internal.CommonProvider.InsertProvider`1.ToSqlValuesOrSelectUnionAllExtension101(Boolean isValues, Action`3 onrow)
   at FreeSql.MySql.Curd.MySqlInsertOrUpdate`1.<>c__DisplayClass1_0.<ToSql>g__getInsertSql|2(List`1 data, Boolean flagInsert, Boolean noneParameter)
   at FreeSql.MySql.Curd.MySqlInsertOrUpdate`1.<>c__DisplayClass1_0.<ToSql>b__0(List`1 a)
   at System.Linq.Enumerable.SelectArrayIterator`2.MoveNext()
   at System.String.Join(String separator, IEnumerable`1 values)
   at FreeSql.MySql.Curd.MySqlInsertOrUpdate`1.ToSql()
   at FreeSql.Internal.CommonProvider.InsertOrUpdateProvider`1.RawExecuteAffrows()
   at FreeSql.Internal.CommonProvider.InsertOrUpdateProvider`1.ExecuteAffrows()
   at FreeSqlGlobalExtensions.InsertOrUpdateDictImpl.ExecuteAffrows()
   at PipeApplication.Connector.RDB.Base.RdbSinkBase.InsertData(DataTable dt) in C:\Users\WBS\RiderProjects\WareHouse\Module\Pipe\PipeApplication\Connector\RDB\Base\RdbSinkBase.cs:line 41
   at PipeApplication.Connector.RDB.Base.RdbSubBase.<>c__DisplayClass0_0.<Run>b__0() in C:\Users\WBS\RiderProjects\WareHouse\Module\Pipe\PipeApplication\Connector\RDB\Base\RdbSubBase.cs:line 21
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__272_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)

数据库版本

mysql 5.7

安装的Nuget包

最新版

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

6

@wangboshun
Copy link
Contributor Author

我是想存在就跳过,不存在就插入。

@wangboshun wangboshun changed the title 更新插入字典失败 插入字典失败 Aug 24, 2023
@2881099
Copy link
Collaborator

2881099 commented Aug 24, 2023

.IfExistsDoNothing 在 mysql 下有问题,等待修复

@2881099
Copy link
Collaborator

2881099 commented Aug 24, 2023

v3.2.701-preview20230824 过几分钟后更新

@wangboshun
Copy link
Contributor Author

Mysql支持insert ignore,insert replace等几种插入语法,用这个更快些

@wangboshun
Copy link
Contributor Author

语句简单些

@2881099
Copy link
Collaborator

2881099 commented Aug 24, 2023

谢谢反馈,已优化 v3.2.701-preview20230824

@wangboshun
Copy link
Contributor Author

Pgsql也支持这个语法

@wangboshun
Copy link
Contributor Author

Sqlite也支持,sqlserver不支持,其他的一些数据库我也不知道😉

@2881099
Copy link
Collaborator

2881099 commented Aug 25, 2023

pgsql 有 On Conflict Do Update

sqlserver 有 merge into

都可以实现 IfExistsDoNothing,并且可以指定字段来判断

replace ignore 这些只能根据主键,或唯一键

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