Hello,

It appears that System.Nullable<system.decimal>.GetValueOrDefault' is not fully supported with Microsoft SQL Server storage (connectionUrl="sqlserver://localhost\SQLEXPRESS/MyDataBase").

Here is some sample code to reproduce the bug (The same code works fine with connectionUrl="memory://localhost/DO40-Tests") An exception is thrown at the call to myEntity.Lines.Sum<line>(l => l.Amount.GetValueOrDefault());

class Program
  {
    static void Main(string[] args)
    {
      // Loading configuration section for in-memory database. 
      // See other cases in App.config file.
      var config = DomainConfiguration.Load("Default");
      var domain = Domain.Build(config);

      using (Session.Open(domain))
      {
        using (var transactionScope = Transaction.Open())
        {
          // Creating new persistent object
          var helloWorld = new MyEntity
          {
            Text = "Hello World!"
          };
          // Committing transaction
          transactionScope.Complete();
        }
      }

      // Reading all persisted objects from another Session
      using (Session.Open(domain))
      {
        using (var transactionScope = Transaction.Open())
        {
          foreach (var myEntity in Query<MyEntity>.All)
          {
            Console.WriteLine(myEntity.Text); // OK 
            decimal total = myEntity.Lines.Sum<Line>(l => l.Amount.GetValueOrDefault()); // exception occurs here
            Console.WriteLine("Total = " + total);
          }
          transactionScope.Complete();
        }
      }
      Console.ReadKey();
    }
  }
  [HierarchyRoot]
  public class MyEntity : Entity
  {
    [Field, Key]
    public int Id { get; private set; }
    [Field(Length = 100)]
    public string Text { get; set; }
    [Field, Association(PairTo = "Owner", OnOwnerRemove = OnRemoveAction.Clear)]
    public EntitySet<Line> Lines { get; private set; }
  }

  [HierarchyRoot]
  public class Line : Entity
  {
    [Field, Key]
    public int Id { get; private set; }
    [Field]
    public MyEntity Owner { get; set; }
    [Field]
    public decimal? Amount { get; set; }
  }

The following exception occurs :

L'exception System.NotSupportedException n'a pas été gérée
  Message="Member 'System.Nullable<System.Decimal>.GetValueOrDefault' is not supported."
  Source="Xtensive.Storage.Providers.Sql"
  StackTrace:
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.CompileMember(MemberInfo member, SqlExpression instance, SqlExpression[] arguments) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.Helpers.cs:line 165
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.VisitMethodCall(MethodCallExpression mc) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 295
       at Xtensive.Core.Linq.ExpressionVisitor`1.Visit(Expression e) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Linq\ExpressionVisitor{TResult}.cs:line 106
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Visit(Expression e, Boolean smartNull) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 72
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Visit(Expression e) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 60
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.VisitUnary(UnaryExpression expression) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 110
       at Xtensive.Core.Linq.ExpressionVisitor`1.Visit(Expression e) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Linq\ExpressionVisitor{TResult}.cs:line 63
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Visit(Expression e, Boolean smartNull) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 72
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Visit(Expression e) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 60
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.VisitLambda(LambdaExpression l) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 333
       at Xtensive.Core.Linq.ExpressionVisitor`1.Visit(Expression e) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Linq\ExpressionVisitor{TResult}.cs:line 109
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Visit(Expression e, Boolean smartNull) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 72
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Visit(Expression e) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 60
       at Xtensive.Storage.Providers.Sql.Expressions.ExpressionProcessor.Translate() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\Expressions\ExpressionProcessor.cs:line 54
       at Xtensive.Storage.Providers.Sql.SqlCompiler.ProcessExpression(LambdaExpression le, List`1[] sourceColumns) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SqlCompiler.Helpers.cs:line 71
       at Xtensive.Storage.Providers.Sql.SqlCompiler.VisitCalculate(CalculateProvider provider) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SqlCompiler.cs:line 107
       at Xtensive.Storage.Rse.Compilation.Compiler`1.Compile(CompilableProvider cp) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Rse\Compilation\Compiler.cs:line 78
       at Xtensive.Storage.Providers.Sql.SqlCompiler.VisitAggregate(AggregateProvider provider) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Providers.Sql\SqlCompiler.Aggregate.cs:line 22
       at Xtensive.Storage.Rse.Compilation.Compiler`1.Compile(CompilableProvider cp) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Rse\Compilation\Compiler.cs:line 72
       at Xtensive.Storage.Rse.Compilation.Compiler`1.Xtensive.Storage.Rse.Compilation.ICompiler.Compile(CompilableProvider provider) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Rse\Compilation\Compiler.cs:line 47
       at Xtensive.Storage.Rse.Compilation.CompilationContext.Compile(CompilableProvider provider) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Rse\Compilation\CompilationContext.cs:line 129
       at Xtensive.Storage.Rse.RecordSet.<GetEnumerator>d__4.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage.Rse\RecordSet.cs:line 67
       at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
       at Xtensive.Core.Collections.EnumerableExtensions.<Batch>d__27`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 487
       at Xtensive.Core.Collections.EnumerableExtensions.<ApplyBeforeAndAfter>d__2f`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Collections\EnumerableExtensions.cs:line 579
       at Xtensive.Storage.Linq.Materialization.MaterializationHelper.<BatchMaterialize>d__3`1.MoveNext() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage\Linq\Materialization\MaterializationHelper.cs:line 132
       at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
       at lambda_method(ExecutionScope , Object[] , IEnumerable`1 , Dictionary`2 )
       at Xtensive.Core.Helpers.DelegateBindExtensions.<>c__DisplayClassa`4.<Bind>b__9(T2 arg2, T3 arg3) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Core\Xtensive.Core\Helpers\DelegateBindExtensions.cs:line 46
       at Xtensive.Storage.Linq.TranslatedQuery`1.Execute() in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage\Linq\TranslatedQuery{TResult}.cs:line 32
       at Xtensive.Storage.Linq.QueryProvider.Execute[TResult](Expression expression) in c:\TeamCity\buildAgent\work\6a5d81309423096e\Xtensive.Storage\Xtensive.Storage\Linq\QueryProvider.cs:line 59
       at System.Linq.Queryable.Sum[TSource](IQueryable`1 source, Expression`1 selector)
       at DoSimpleTests.Program.Main(String[] args) in D:\Projets\DO4\DoSimpleTests\DoSimpleTests\Program.cs:line 39
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

Best regards,

Auguste


Updated at 09.12.2009 14:49:17

Thank you very much for fixing this issue ! :D I am looking forward to using the corresponding daily build (the latest build available was posted on 3/12/2009, before you fixed the issue). Best regards, Auguste

This thread was imported from our support forum. The original discussion may contain more detailed answer.

asked Dec 04 '09 at 11:03

Auguste's gravatar image

Auguste
25888


One Answer:

Nullable<t>.GetValueOrDefault isn't supported at all. Memory storage supports everything just because there is no real necessity to translate the expressions for it - they execute "as is" there.

So what's supported for Nullable<t>? See NullableCompilers.cs, it shows we support just Value and HasValue methods.

I ask the team to implement GetValueOrDefault() for Nullable<t> - initially this looks like a pretty simple task.

P.S. You can try to write it by your own - recently we described how to extend our LINQ translator: http://dataobjectsdotnet.googlecode.com ... edLinq.htm


That's because the only build agent fully configured for building nightly builds is down now. We've moved our servers to different location on the previous week, and AgentJohnson is the only one that didn't survive (funny, but we noticed this just on this week - all the tests were running on other agents). We'll fix this ASAP.

For now you can try repository @ Google Code - it contains the latest bits (currently we update it almost daily).

answered Dec 04 '09 at 17:14

Alex%20Yakunin's gravatar image

Alex Yakunin
29714412

Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
toggle preview

Subscription:

Once you sign in you will be able to subscribe for any updates here

Tags:

×573

Asked: Dec 04 '09 at 11:03

Seen: 7,386 times

Last updated: Dec 04 '09 at 11:03

powered by OSQA