question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception thrown: Expression 'display.PageNumber' is not a Field using Value on Insertable

See original GitHub issue

Using the Value method when doing an Insert throws ‘Expression is not a Field exception’

When using the Value method when doing an Insert, the following exception is thrown if the value parameter is not an Expression. This seems wrong as there are two overloads on this method, once which takes a Value:

		public static ISelectInsertable<TSource,TTarget> Value<TSource,TTarget,TValue>(
			                this ISelectInsertable<TSource,TTarget> source,
			[InstantHandle] Expression<Func<TTarget,TValue>>        field,
			TValue                                                  value)

and one which takes an expression:

		public static ISelectInsertable<TSource,TTarget> Value<TSource,TTarget,TValue>(
			                this ISelectInsertable<TSource,TTarget> source,
			[InstantHandle] Expression<Func<TTarget,TValue>>        field,
			[InstantHandle] Expression<Func<TSource,TValue>>        value)

I would expect both to work. If the first method doesn’t work, why does it exist? This turned out to be quite a serious problem as the code compiled but failed at runtime.

Exception message:
LinqToDB.Linq.LinqException: Expression 'display.PageNumber' is not a Field.

Stack trace:
at LinqToDB.Linq.Builder.TableBuilder.TableContext.ConvertToSql(Expression expression, Int32 level, ConvertFlags flags)
   at LinqToDB.Linq.Builder.UpdateBuilder.ParseSet(ExpressionBuilder builder, LambdaExpression extract, MethodCallExpression updateMethod, Int32 valueIndex, IBuildContext select, List`1 items)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.Value.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.InsertBuilder.BuildMethodCall(ExpressionBuilder builder, MethodCallExpression methodCall, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.MethodCallBuilder.BuildSequence(ExpressionBuilder builder, BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.BuildSequence(BuildInfo buildInfo)
   at LinqToDB.Linq.Builder.ExpressionBuilder.Build[T]()
   at LinqToDB.Linq.Query`1.CreateQuery(ExpressionTreeOptimizationContext optimizationContext, ParametersContext parametersContext, IDataContext dataContext, Expression expr)
   at LinqToDB.Linq.Query`1.GetQuery(IDataContext dataContext, Expression& expr, Boolean& dependsOnParameters)
   at LinqToDB.Linq.ExpressionQuery`1.GetQuery(Expression& expression, Boolean cache, Boolean& dependsOnParameters)
   at LinqToDB.Linq.ExpressionQuery`1.<LinqToDB-Async-IQueryProviderAsync-ExecuteAsync>d__15`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LinqToDB.LinqExtensions.<InsertAsync>d__92`2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Service.Commands.DisplayUpdateCommand.<DisplayInsertCommand>d__9.MoveNext()

Steps to reproduce


var serialNumber = "12345678901";
var pageNum = 9;
await _dbConnection.Displays
                .Where(display => display.SerialNumber == serialNumber)
                .Into(_dbConnection.Displays)
                .Value(display => display.PageNumber, pageNumber)
                .InsertAsync();

Model


[Table(Schema="dbo", Name="Display")]
public partial class Display
{
	[Column(DataType=LinqToDB.DataType.Char,   Length=11),   PrimaryKey, NotNull ] public string  SerialNumber    { get; set; } // char(11)
	[Column(DataType=LinqToDB.DataType.Int32),   NotNull ] public int            PageNumber                          { get; set; } // int
}

Environment details

Linq To DB version: 4.1.1

Database (with version): SQL Server 2016

ADO.NET Provider (with version): Microsoft.Data.SqlClient 4.1.0

Operating system: Windows Server 2019

.NET Version: .Net Framework 4.7.2

Issue Analytics

  • State:open
  • Created 8 months ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
DDSGoochcommented, Jan 25, 2023

Thanks for your quick and helpful replies, I look forward to trying out the new version and keep up the good work. It’s a great package and so much preferable to using Entity Framework.

0reactions
sdanylivcommented, Jan 25, 2023

Version 5 have a lot of improvements but version 6 will have redesigned LINQ translator. Almost done but for release it is about several months. In short, if it is not critical we can spend efforts on version 6.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Spring boot 2.0.3. REALESE and Thymeleaf data bing
When I run the addUser method, I get the following error emphasized textThis application has no explicit mapping for /error, so you are...
Read more >
SQL error messages and exceptions
An expression containing the column ' <columnName> ' appears in the SELECT list and is not part of a GROUP BY clause. 42815,...
Read more >
Spring Data JPA Tutorial: Pagination
This blog post describes how you can paginate your query results with Spring Data JPA.
Read more >
LibreOffice Developer's Guide: Chapter 7 - Text Documents
We want to use a template file containing text fields and bookmarks and insert text into the fields and at the cursor position....
Read more >
Cognos Analytics 11.0 Fix Lists
A comprehensive list of defect corrections for major releases, refresh packs and fix packs of Cognos Analytics 11.0.x.0 Details of the APARs ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found