Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing an issue with processing indexes using FirstOrDefault on compl…

…ex value types
  • Loading branch information...
commit e336a3bb18f313f1f402e53ab4d08f85698fd68e 1 parent 42a17c1
@ayende ayende authored
View
18 Raven.Client.Lightweight/Indexes/ExpressionStringBuilder.cs
@@ -234,8 +234,9 @@ private void OutMember(Expression instance, MemberInfo member, Type exprType)
}
if (instance != null)
{
+ Out("(");
Visit(instance);
- Out("." + name);
+ Out(")." + name);
}
else
{
@@ -918,10 +919,14 @@ private string ConvertTypeToCSharpKeyword(Type type)
{
if (type.IsGenericType)
{
+ if(TypeExistsOnServer(type) == false)
+ throw new InvalidOperationException("Cannot make use of type " + type + " because it is a generic type that doesn't exists on the server");
var typeDefinition = type.GetGenericTypeDefinition();
- var sb = new StringBuilder(typeDefinition.FullName, 0);
- sb.Length = typeDefinition.FullName.IndexOf('`');
- sb.Replace('+', '.');
+ var sb = new StringBuilder(typeDefinition.FullName, 0)
+ {
+ Length = typeDefinition.FullName.IndexOf('`')
+ };
+ sb.Replace('+', '.');
sb.Append("<");
var arguments = type.GetGenericArguments();
@@ -1014,7 +1019,10 @@ private string ConvertTypeToCSharpKeyword(Type type)
{
return "byte?";
}
-
+ if (type.IsEnum)
+ {
+ return "string";
+ }
if (type.FullName == "System.Object")
{
return "object";
View
5 Raven.Database/Linq/AbstractTransformer.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Raven.Abstractions.Indexing;
+using Raven.Abstractions.Linq;
using Raven.Database.Indexing;
using Raven.Json.Linq;
@@ -15,6 +16,10 @@ public abstract class AbstractTransformer
public string ViewText { get; set; }
+ // ReSharper disable once InconsistentNaming
+ protected DynamicNullObject __dynamic_null = new DynamicNullObject();
+
+
protected dynamic LoadDocument(object key)
{
if (CurrentTransformationScope.Current == null)
View
3  Raven.Database/Linq/AbstractViewGenerator.cs
@@ -35,6 +35,9 @@ public abstract class AbstractViewGenerator
private readonly HashSet<string> mapFields = new HashSet<string>();
private readonly HashSet<string> reduceFields = new HashSet<string>();
+// ReSharper disable once InconsistentNaming
+ protected DynamicNullObject __dynamic_null = new DynamicNullObject();
+
private static readonly Regex selectManyOrFrom = new Regex(@"( (?<!^)\s from \s ) | ( \.SelectMany\( )",
RegexOptions.Compiled |
RegexOptions.IgnorePatternWhitespace);
View
5 Raven.Database/Linq/Ast/TransformNullCoalescingOperatorTransformer.cs
@@ -19,8 +19,9 @@ public override object VisitBinaryOperatorExpression(BinaryOperatorExpression bi
if(binaryOperatorExpression.Operator==BinaryOperatorType.NullCoalescing)
{
var node = new ConditionalExpression(
- new BinaryOperatorExpression(binaryOperatorExpression.Left.Clone(), BinaryOperatorType.InEquality,
- new PrimitiveExpression(null, null)),
+ new BinaryOperatorExpression(new MemberReferenceExpression(new ThisReferenceExpression(), "__dynamic_null")
+ , BinaryOperatorType.InEquality,
+ binaryOperatorExpression.Left.Clone()),
binaryOperatorExpression.Left.Clone(),
binaryOperatorExpression.Right.Clone()
);
View
1  Raven.Database/Util/PerformanceCounterWrapper.cs
@@ -42,6 +42,7 @@ public long Decrement()
}
catch (Exception)
{
+ return -1;
}
}
View
73 Raven.Tests/MailingList/DictionaryOfEnum.cs
@@ -0,0 +1,73 @@
+// -----------------------------------------------------------------------
+// <copyright file="DictionaryOfEnum.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+using System.Collections.Generic;
+using System.Linq;
+using Raven.Client.Indexes;
+using Xunit;
+
+namespace Raven.Tests.MailingList
+{
+ public class DictionaryOfEnum : RavenTest
+ {
+ public enum MyEnum
+ {
+ Value1,
+ Value2
+ }
+
+ public class Test
+ {
+ public string Id;
+ public Dictionary<MyEnum, string> Name { get; set; }
+ }
+
+ public class Result
+ {
+ public string Id;
+ public string Name;
+ }
+
+ public class MyTransformer : AbstractTransformerCreationTask<Test>
+ {
+ public MyTransformer()
+ {
+ TransformResults = results =>
+ from result in results
+ select new
+ {
+ Name = result.Name.FirstOrDefault(a => a.Key == MyEnum.Value1).Value
+ };
+ }
+ }
+
+ [Fact]
+ public void ShouldWork()
+ {
+ using (var store = NewDocumentStore())
+ {
+ new MyTransformer().Execute(store);
+ using (var s = store.OpenSession())
+ {
+ s.Store(new Test
+ {
+ Name = new Dictionary<MyEnum, string>
+ {
+ {MyEnum.Value1, "t"},
+ {MyEnum.Value2, "b"}
+ }
+ });
+ s.SaveChanges();
+
+ var myTransformer = s.Load<MyTransformer, Result>("tests/1");
+ Assert.Equal("t", myTransformer.Name);
+ }
+
+
+ }
+ }
+
+ }
+}
View
1  Raven.Tests/Raven.Tests.csproj
@@ -750,6 +750,7 @@
<Compile Include="MailingList\ConcurrencyTests2.cs" />
<Compile Include="MailingList\CustomizingIndexQuery.cs" />
<Compile Include="MailingList\DateTimeOffsetIssues.cs" />
+ <Compile Include="MailingList\DictionaryOfEnum.cs" />
<Compile Include="MailingList\DifferentKeysWithTheSameFirst127CharactersAreDifferent.cs" />
<Compile Include="MailingList\DistinctWithPaging.cs" />
<Compile Include="MailingList\DynamicFieldNoAnalysisStillAnalyzesTest.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.