Update with clouser problem. The multi-part identifier "order.Comment" could not be bound
I have a problem with this code:
using (var context = new DataContext())
{
context.Order
.Where(order => order.OrderId == 1)
.Update(x => new Order()
{
Comment = (x.Comment != null ? x.Comment + "\r\n" : "") + " TEST"
});
}
public partial class Order
{
public int OrderId { get; set; }
public string Comment { get; set; }
}
}
Exception
[SqlException (0x80131904): The multi-part identifier "order.Comment" could not be bound.
The multi-part identifier "order.Comment" could not be bound.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +266 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) +98
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +988
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +6523
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async, Int32 timeout, Boolean asyncWrite) +1491
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) +523 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +387 Z.EntityFramework.Plus.BatchUpdate.Execute(IQueryable1 query, Expression1 updateFactory) +2474 Z.EntityFramework.Plus.BatchUpdateExtensions.Update(IQueryable1 query, Expression1 updateFactory, Action1 batchUpdateBuilder) +194
Z.EntityFramework.Plus.BatchUpdateExtensions.Update(IQueryable1 query, Expression1 updateFactory) +82
Generated SQL
UPDATE A
SET A.[Comment] = CASE
WHEN [order].[Comment] IS NOT NULL
THEN [order].[Comment] + N'
' ELSE N''
END + N' TEST'
FROM [Order] AS A
INNER JOIN ( SELECT [order].[OrderId], [order].[AccessOpenCode]...
FROM [Order] AS [order]
WHERE [order].[OrderId] = 1
) AS B ON A.[OrderId] = B.[OrderId]
Further technical details
Z.EntityFramework.Extensions.EFCore version="2.7.20" Z.EntityFramework.Plus.EFCore" version="2.0.24" Z.Expressions.Eval" version="3.0.7" Microsoft.EntityFrameworkCore" version="2.2.6" Database Provider: MSSQL .NET 4.8
Hello @API-kernel ,
Thank you for reporting. we will look at it.
Performance Libraries
context.BulkInsert(list, options => options.BatchSize = 1000);
Entity Framework Extensions • Entity Framework Classic • Bulk Operations • Dapper Plus
Runtime Evaluation
Eval.Execute("x + y", new {x = 1, y = 2}); // return 3
C# Eval Function • SQL Eval Function
Rank = f.Rank
});
Hello @API-kernel ,
Could you try the following LINQ
using (var context = new DataContext())
{
context.Order
.Where(order => order.OrderId == 1)
.Update(order => new Order()
{
Comment = (order.Comment != null ? order.Comment + "\r\n" : "") + " TEST"
});
}
My developer told me we currently have a limitation for this query and using the same lambda parameter name will make it works.
If that really works, we will investigate more why that's hapenning
Hi Yes, it work, thx. Hope this will be fixed =)