efcore icon indicating copy to clipboard operation
efcore copied to clipboard

FromSql throws ArgumentNullException when passing a null parameter

Open dealdiane opened this issue 11 years ago • 1 comments

Suppose we have a stored procedure

CREATE PROCEDURE GetPersons @departmentid INT AS SELECT * FROM People WHERE DepartmentId = COALESCE(@departmentid, DepartmentID)

Calling that stored procedure using the code below causes an exception.

int? departmentId = null;
db.Set<Person>().FromSql(@"GetPersons @departmentid = {0}", departmentId)

Full stack trace:

ArgumentNullException: Value cannot be null. Parameter name: value

Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
Microsoft.Data.Entity.Query.CommandParameter..ctor(String name, Object value, RelationalTypeMapping typeMapping)
Microsoft.Data.Entity.Query.Sql.DefaultQuerySqlGenerator.VisitRawSqlDerivedTable(RawSqlDerivedTableExpression rawSqlDerivedTableExpression)
Microsoft.Data.Entity.Query.Expressions.RawSqlDerivedTableExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
Microsoft.Data.Entity.Query.Sql.DefaultQuerySqlGenerator.<VisitJoin>b__30_0(Expression e)
Microsoft.Data.Entity.Query.Sql.DefaultQuerySqlGenerator.VisitJoin[T](IReadOnlyList`1 items, Action`1 itemAction, Action`1 joinAction)
Microsoft.Data.Entity.Query.Sql.DefaultQuerySqlGenerator.VisitJoin(IReadOnlyList`1 expressions, Action`1 joinAction)
Microsoft.Data.Entity.Query.Sql.DefaultQuerySqlGenerator.VisitSelect(SelectExpression selectExpression)
Microsoft.Data.Entity.Query.Expressions.SelectExpression.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Remotion.Linq.Parsing.ThrowingExpressionVisitor.Visit(Expression expression)
Microsoft.Data.Entity.Query.Sql.DefaultQuerySqlGenerator.GenerateSql(IDictionary`2 parameterValues)
Microsoft.Data.Entity.Query.Expressions.SelectExpression.ToString()
Microsoft.Data.Entity.Query.Internal.RelationalExpressionPrinter.CommandBuilderPrinter.TryPrintConstant(Object value, IndentedStringBuilder stringBuilder)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitConstant(ConstantExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitLambda[T](Expression`1 node)
System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitLambda[T](Expression`1 node)
System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.VisitLambda[T](Expression`1 node)
System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Visit(Expression node)
Microsoft.Data.Entity.Query.Internal.ExpressionPrinter.Print(Expression expression)
Microsoft.Data.Entity.Query.EntityQueryModelVisitor.<>c__DisplayClass36_0`1.<CreateExecutorLambda>b__0()
Microsoft.Framework.Logging.LoggingExtensions.<>c__DisplayClass0_0.<LogInformation>b__0(Object _)
Microsoft.Framework.Logging.LoggingExtensions.<>c__DisplayClass3_0`1.<LogInformation>b__0(Object s, Exception _)
Microsoft.Framework.Logging.Console.ConsoleLogger.Log(LogLevel logLevel, Int32 eventId, Object state, Exception exception, Func`3 formatter)
Microsoft.Framework.Logging.Logger.Log(LogLevel logLevel, Int32 eventId, Object state, Exception exception, Func`3 formatter)

dealdiane avatar Oct 15 '15 02:10 dealdiane

I was able to reproduce this issue using beta7 and verified that it has been resolved in beta8. Added test coverage with #3432 to detect potential future regressions.

mikary avatar Oct 19 '15 19:10 mikary