diff --git a/MongoDB-CSharp.sln b/MongoDB-CSharp.sln index 007cc71d..51f9e227 100644 --- a/MongoDB-CSharp.sln +++ b/MongoDB-CSharp.sln @@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Tests", "source\Mon EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Benchmark", "tools\Benchmark\Benchmark.csproj", "{5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.DataContext", "source\MongoDB.DataContext\MongoDB.DataContext.csproj", "{5E413F58-FA04-4C9A-96B9-12AD43731C24}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -53,6 +55,10 @@ Global {5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Debug|Any CPU.Build.0 = Debug|Any CPU {5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Release|Any CPU.ActiveCfg = Release|Any CPU {5ACD68A0-0F2E-452A-90E3-3D1CB82C055B}.Release|Any CPU.Build.0 = Release|Any CPU + {5E413F58-FA04-4C9A-96B9-12AD43731C24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E413F58-FA04-4C9A-96B9-12AD43731C24}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E413F58-FA04-4C9A-96B9-12AD43731C24}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E413F58-FA04-4C9A-96B9-12AD43731C24}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs b/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs index 639a760f..1c57ecb1 100644 --- a/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs +++ b/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs @@ -1,31 +1,33 @@ using System.Collections.Generic; +using MongoDB.Attributes; + namespace MongoDB.IntegrationTests.Linq { public class Person { - //[MongoAlias("fn")] + [MongoAlias("fn")] public string FirstName { get; set; } - //[MongoAlias("ln")] + [MongoAlias("ln")] public string LastName { get; set; } - //[MongoAlias("age")] + [MongoAlias("age")] public int Age { get; set; } - //[MongoAlias("add")] + [MongoAlias("add")] public Address PrimaryAddress { get; set; } - //[MongoAlias("otherAdds")] + [MongoAlias("otherAdds")] public List
Addresses { get; set; } - //[MongoAlias("emps")] + [MongoAlias("emps")] public int[] EmployerIds { get; set; } } public class Address { - //[MongoAlias("city")] + [MongoAlias("city")] public string City { get; set; } public bool IsInternational { get; set; } diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs index 76f2b3c5..0b9417d2 100644 --- a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs +++ b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs @@ -159,8 +159,8 @@ public void Count_without_predicate() public void DocumentQuery() { var people = (from p in DocumentCollection.Linq() - where p.Key("Age") > 21 - select (string)p["FirstName"]).ToList(); + where p.Key("age") > 21 + select (string)p["fn"]).ToList(); Assert.AreEqual(2, people.Count); } diff --git a/source/MongoDB/Linq/MongoQueryProvider.cs b/source/MongoDB/Linq/MongoQueryProvider.cs index 521c2b2e..fdd5f033 100644 --- a/source/MongoDB/Linq/MongoQueryProvider.cs +++ b/source/MongoDB/Linq/MongoQueryProvider.cs @@ -259,7 +259,6 @@ private object ExecuteMapReduce(MongoQueryObject queryObject) var mapReduce = collection.GetType().GetMethod("MapReduce").Invoke(collection, null); var mapReduceCommand = (MapReduceCommand)mapReduce.GetType().GetProperty("Command").GetValue(mapReduce, null); - mapReduceCommand.Map = new Code(queryObject.MapFunction); mapReduceCommand.Reduce = new Code(queryObject.ReduceFunction); mapReduceCommand.Finalize = new Code(queryObject.FinalizerFunction); @@ -273,11 +272,8 @@ private object ExecuteMapReduce(MongoQueryObject queryObject) if (queryObject.NumberToSkip != 0) throw new InvalidQueryException("MapReduce queries do no support Skips."); - //mapReduce.GetType().GetProperty() - var executor = GetExecutor(typeof(Document), queryObject.Projector, queryObject.Aggregator, true); - return null; - //executor.Compile().DynamicInvoke(mapReduce.Documents); + return executor.Compile().DynamicInvoke(mapReduce.GetType().GetProperty("Documents").GetValue(mapReduce, null)); } private static LambdaExpression GetExecutor(Type documentType, LambdaExpression projector, LambdaExpression aggregator, bool boxReturn) diff --git a/source/MongoDB/MapReduce.cs b/source/MongoDB/MapReduce.cs index d5524778..d9ac3849 100644 --- a/source/MongoDB/MapReduce.cs +++ b/source/MongoDB/MapReduce.cs @@ -47,7 +47,7 @@ public MapReduce(IMongoDatabase database, string name) /// Gets the documents. /// /// The documents. - public IEnumerable Documents + public IEnumerable Documents { get { @@ -56,7 +56,7 @@ public IEnumerable Documents if(Result == null || Result.Ok == false) throw new InvalidOperationException("Documents cannot be iterated when an error was returned from execute."); - var docs = _database.GetCollection().FindAll().Documents; + var docs = _database.GetCollection(Result.CollectionName).FindAll().Documents; using((IDisposable)docs) { foreach(var doc in docs) @@ -228,7 +228,7 @@ internal void RetrieveData() try { - Result = new MapReduceResult(_database.SendCommand(Command.Command)); + Result = new MapReduceResult(_database.SendCommand(typeof(T), Command.Command)); } catch(MongoCommandException exception) { diff --git a/source/MongoDB/Serialization/BsonClassMapDescriptor.cs b/source/MongoDB/Serialization/BsonClassMapDescriptor.cs index 2a065253..a5ef9df8 100644 --- a/source/MongoDB/Serialization/BsonClassMapDescriptor.cs +++ b/source/MongoDB/Serialization/BsonClassMapDescriptor.cs @@ -11,6 +11,7 @@ internal class BsonClassMapDescriptor : IBsonObjectDescriptor { private readonly Stack _types; private readonly IMappingStore _mappingStore; + private bool _isMapReduce; public BsonClassMapDescriptor(IMappingStore mappingStore, Type rootType) { @@ -91,6 +92,9 @@ private object BeginDocument(Document document) var currentClassMap = _mappingStore.GetClassMap(_types.Peek()); + //var doc = (Document)instance; + //if (doc.ContainsKey("mapreduce")) + // _isMapReduce = true; return new DocumentClassMapPropertyDescriptor(_mappingStore, currentClassMap, document); } diff --git a/source/MongoDB/Serialization/Descriptors/ClassMapPropertyDescriptorBase.cs b/source/MongoDB/Serialization/Descriptors/ClassMapPropertyDescriptorBase.cs index f41cf9ed..6fd529d3 100644 --- a/source/MongoDB/Serialization/Descriptors/ClassMapPropertyDescriptorBase.cs +++ b/source/MongoDB/Serialization/Descriptors/ClassMapPropertyDescriptorBase.cs @@ -271,7 +271,7 @@ private string MatchMember() { StringBuilder memberName = new StringBuilder(); char c = Current; - while (c != '.' && c != ' ' && c != '(' && c != '[' && c != EOF) + while (Char.IsLetterOrDigit(c) || c == '_' || c == '$') { ReadChar(false); memberName.Append(c);