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
更新实体的问题 #143
Comments
SetSource 适合更新整个实体,有主键的实体。 换个方法 var returnValue = await _freeSql.Update() |
好像这样也是不行的。 |
你试一下,😄 |
我现在只能写成这样。
|
.Set(a=> new UserAuth { 这种不成吗? |
不行的,连tosql()也不会出来的。 |
不用主键也可以,只有 where 条件存在,则执行 当没有 set 子句时,也是直接返回 0 |
你用的是sqllite的,我是mssql的,这个有关系吗? |
没有关系,里面走的代码是一样的 |
这个是表达式解析,不能直接Set实体,解不出要更新的字段 |
如果是Set T呢? |
SetSource 更新整个实体所有字段,但是需要实体有主键值,这种情况不用给为条件,它会自动把实体的主键作为条件。 |
where set 任何为空,都不执行sql,安全考虑 |
var userAuth = new UserAuth();
userAuth.F_RoleType = _model.F_RoleType;
userAuth.F_UseType = _model.F_RoleType;
var returnValue = await _freeSql.Update()
.Where(p => p.F_EmpId == _model.F_EmpId)
.SetSource(userAuth)
.ExecuteAffrowsAsync();
上面代码是更新数据,但empid不是主键。用这种方式执行会报错。
{
"messages": [
"An error ocurred."
],
"developerMessage": {
"ClassName": "System.Data.SqlClient.SqlException",
"Message": "“)”附近有语法错误。",
"Data": {
"HelpLink.ProdName": "Microsoft SQL Server",
"HelpLink.ProdVer": "11.00.3128",
"HelpLink.EvtSrc": "MSSQLServer",
"HelpLink.EvtID": "102",
"HelpLink.BaseHelpUrl": "https://go.microsoft.com/fwlink",
"HelpLink.LinkId": "20476",
"SqlError 1": "System.Data.SqlClient.SqlError: “)”附近有语法错误。"
},
"InnerException": null,
"HelpURL": null,
"StackTraceString": " at FreeSql.Internal.CommonProvider.UpdateProvider
1.RawExecuteAffrowsAsync()\r\n at FreeSql.Internal.CommonProvider.UpdateProvider
1.SplitExecuteAffrowsAsync(Int32 valuesLimit, Int32 parameterLimit)\r\n at Account.API.Controllers.identityController.ChangeType(frm_ChangType _model) in C:\dev\erp\src\Services\Account2.API\Controllers\identityController.cs:line 49\r\n at lambda_method(Closure , Object )\r\n at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()\r\n at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n at System.Threading.Tasks.ValueTask`1.get_Result()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextExceptionFilterAsync()","RemoteStackTraceString": null,
"RemoteStackIndex": 0,
"ExceptionMethod": null,
"HResult": -2146232060,
"Source": "Core .Net SqlClient Data Provider",
"WatsonBuckets": null,
"Errors": null,
"ClientConnectionId": "e1b53e4e-fd42-418d-93c5-a24726a9b7b2"
}
}
{"code":500,"mes":"UPDATE [UserAuth] SET [F_SUId] = @p_0, [F_EmpId] = @p_1, [F_UserId] = @p_2, [F_ComId] = @p_3, [F_UseType] = @p_4, [F_OrgGuids] = @p_5, [F_RoleType] = @p_6, [F_RoleId] = @p_7 \r\nWHERE () AND ( F_EmpId='d3ec7e01-e85c-4024-b15e-d18795d2cefb' )","data":null,"record":null,"second":""}
调试是发现where里面是空的。
The text was updated successfully, but these errors were encountered: