Skip to content
Permalink
Browse files

Initial core refactor of entity mapping system

Code builds - tests not run
  • Loading branch information...
Turnerj committed May 12, 2019
1 parent bc42be8 commit c6ebe58d8f7cb7be133c95793db3301056562a08
Showing with 1,359 additions and 1,521 deletions.
  1. +7 −8 README.md
  2. +1 −0 src/MongoFramework.Profiling.MiniProfiler/MiniProfilerDiagnosticListener.cs
  3. +2 −1 src/MongoFramework/Attributes/CreatedDateAttribute.cs
  4. +0 −48 src/MongoFramework/Attributes/IncrementNumberAttribute.cs
  5. +2 −3 src/MongoFramework/Attributes/IndexAttribute.cs
  6. +4 −3 src/MongoFramework/Attributes/MutatePropertyAttribute.cs
  7. +2 −1 src/MongoFramework/Attributes/UpdatedDateAttribute.cs
  8. +2 −4 src/MongoFramework/IMongoDbConnection.cs
  9. +0 −1 src/MongoFramework/Infrastructure/Commands/UpdateEntityCommand.cs
  10. +1 −0 src/MongoFramework/Infrastructure/DefinitionHelpers/UpdateDefinitionExtensions.cs
  11. +1 −1 src/MongoFramework/Infrastructure/{ → Diagnostics}/DiagnosticCommand.cs
  12. +1 −1 src/MongoFramework/Infrastructure/{ → Diagnostics}/NoOpDiagnosticListener.cs
  13. +2 −5 src/MongoFramework/Infrastructure/EntityBucketCollection.cs
  14. +0 −3 src/MongoFramework/Infrastructure/EntityChangeTracker.cs
  15. +16 −8 src/MongoFramework/Infrastructure/EntityCollection.cs
  16. +16 −17 src/MongoFramework/Infrastructure/{EntityRelationships → }/EntityNavigationCollection.cs
  17. +4 −5 src/MongoFramework/Infrastructure/EntityReader.cs
  18. +14 −13 src/MongoFramework/Infrastructure/{EntityRelationships → }/EntityRelationshipWriter.cs
  19. +0 −13 src/MongoFramework/Infrastructure/EntityRelationships/EntityRelationship.cs
  20. +7 −7 src/MongoFramework/Infrastructure/EntityWriter.cs
  21. +2 −1 src/MongoFramework/Infrastructure/IDiagnosticListener.cs
  22. +2 −1 src/MongoFramework/Infrastructure/{EntityRelationships → }/IEntityNavigationCollection.cs
  23. +1 −1 src/MongoFramework/Infrastructure/{EntityRelationships → }/IEntityRelationshipWriter.cs
  24. +0 −20 src/MongoFramework/Infrastructure/Indexing/DefaultIndexingPack.cs
  25. +0 −9 src/MongoFramework/Infrastructure/Indexing/EntityIndexMap.cs
  26. +0 −58 src/MongoFramework/Infrastructure/Indexing/EntityIndexMapper.cs
  27. +9 −15 src/MongoFramework/Infrastructure/Indexing/EntityIndexWriter.cs
  28. +0 −9 src/MongoFramework/Infrastructure/Indexing/IEntityIndex.cs
  29. +0 −9 src/MongoFramework/Infrastructure/Indexing/IEntityIndexMap.cs
  30. +0 −12 src/MongoFramework/Infrastructure/Indexing/IEntityIndexMapper.cs
  31. +0 −9 src/MongoFramework/Infrastructure/Indexing/IEntityIndexMapperFactory.cs
  32. +0 −10 src/MongoFramework/Infrastructure/Indexing/IIndexingProcessor.cs
  33. +0 −9 src/MongoFramework/Infrastructure/Indexing/IIndexingProcessorPack.cs
  34. +59 −0 src/MongoFramework/Infrastructure/Indexing/IndexModelBuilder.cs
  35. +0 −58 src/MongoFramework/Infrastructure/Indexing/Processors/BasicIndexProcessor.cs
  36. +1 −1 src/MongoFramework/Infrastructure/{ → Internal}/ReflectionExtensions.cs
  37. +3 −3 src/MongoFramework/Infrastructure/Linq/{Processors → }/EntityProcessorCollection.cs
  38. +1 −1 src/MongoFramework/Infrastructure/Linq/ILinqProcessor.cs
  39. +0 −1 src/MongoFramework/Infrastructure/Linq/IMongoFrameworkQueryProvider.cs
  40. +1 −2 src/MongoFramework/Infrastructure/Linq/IMongoFrameworkQueryable.cs
  41. +1 −2 src/MongoFramework/Infrastructure/Linq/MongoFrameworkQueryProvider.cs
  42. +5 −9 src/MongoFramework/Infrastructure/Linq/MongoFrameworkQueryable.cs
  43. +2 −9 src/MongoFramework/Infrastructure/Linq/Processors/EntityMutationProcessor.cs
  44. +1 −1 src/MongoFramework/Infrastructure/Linq/Processors/EntityTrackingProcessor.cs
  45. +5 −2 src/MongoFramework/Infrastructure/Mapping/DefaultMappingPack.cs
  46. +15 −0 src/MongoFramework/Infrastructure/Mapping/EntityDefinition.cs
  47. +111 −0 src/MongoFramework/Infrastructure/Mapping/EntityDefinitionExtensions.cs
  48. +12 −0 src/MongoFramework/Infrastructure/Mapping/EntityIndex.cs
  49. +0 −205 src/MongoFramework/Infrastructure/Mapping/EntityMapper.cs
  50. +126 −0 src/MongoFramework/Infrastructure/Mapping/EntityMapping.cs
  51. +30 −0 src/MongoFramework/Infrastructure/Mapping/EntityProperty.cs
  52. +0 −15 src/MongoFramework/Infrastructure/Mapping/EntityPropertyMap.cs
  53. +13 −0 src/MongoFramework/Infrastructure/Mapping/EntityRelationship.cs
  54. +14 −0 src/MongoFramework/Infrastructure/Mapping/IEntityDefinition.cs
  55. +12 −0 src/MongoFramework/Infrastructure/Mapping/IEntityIndex.cs
  56. +0 −16 src/MongoFramework/Infrastructure/Mapping/IEntityMapper.cs
  57. +0 −9 src/MongoFramework/Infrastructure/Mapping/IEntityMapperFactory.cs
  58. +5 −2 src/MongoFramework/Infrastructure/Mapping/{IEntityPropertyMap.cs → IEntityProperty.cs}
  59. +13 −0 src/MongoFramework/Infrastructure/Mapping/IEntityRelationship.cs
  60. +1 −1 src/MongoFramework/Infrastructure/Mapping/IMappingProcessor.cs
  61. +6 −2 src/MongoFramework/Infrastructure/Mapping/Processors/BsonKnownTypesProcessor.cs
  62. +44 −0 src/MongoFramework/Infrastructure/Mapping/Processors/CollectionNameProcessor.cs
  63. +4 −2 src/MongoFramework/Infrastructure/Mapping/Processors/EntityIdProcessor.cs
  64. +37 −17 ...ntityRelationships/EntityMapperExtensions.cs → Mapping/Processors/EntityRelationshipProcessor.cs}
  65. +3 −1 src/MongoFramework/Infrastructure/Mapping/Processors/ExtraElementsProcessor.cs
  66. +4 −3 src/MongoFramework/Infrastructure/Mapping/Processors/HierarchyProcessor.cs
  67. +26 −0 src/MongoFramework/Infrastructure/Mapping/Processors/IndexProcessor.cs
  68. +2 −1 src/MongoFramework/Infrastructure/Mapping/Processors/MappedPropertiesProcessor.cs
  69. +0 −30 src/MongoFramework/Infrastructure/Mapping/Processors/NavigationPropertyProcessor.cs
  70. +11 −3 src/MongoFramework/Infrastructure/Mapping/Processors/NestedPropertyProcessor.cs
  71. +25 −0 src/MongoFramework/Infrastructure/Mapping/Processors/PropertiesProcessor.cs
  72. +3 −4 src/MongoFramework/Infrastructure/Mapping/Processors/TypeDiscoveryProcessor.cs
  73. +9 −8 src/MongoFramework/Infrastructure/Mutation/Mutators/EntityAttributeMutator.cs
  74. +12 −4 src/MongoFramework/Infrastructure/Mutation/Mutators/NavigationPropertyMutator.cs
  75. +9 −16 ...work/Infrastructure/{EntityRelationships → Serialization}/EntityNavigationCollectionSerializer.cs
  76. +2 −13 src/MongoFramework/Infrastructure/{Mapping → }/Serialization/TypeDiscoverySerializationProvider.cs
  77. +6 −8 src/MongoFramework/Infrastructure/{Mapping → }/Serialization/TypeDiscoverySerializer.cs
  78. +11 −13 src/MongoFramework/Linq/LinqExtensions.cs
  79. +2 −4 src/MongoFramework/MongoDbBucketSet.cs
  80. +3 −35 src/MongoFramework/MongoDbConnection.cs
  81. +1 −2 src/MongoFramework/MongoDbSet.cs
  82. +1 −1 src/MongoFramework/{Infrastructure → }/MongoDbUtility.cs
  83. +4 −9 tests/MongoFramework.Tests/Infrastructure/EntityChangeTrackerTests.cs
  84. +11 −22 tests/MongoFramework.Tests/Infrastructure/EntityCollectionTests.cs
  85. +1 −1 tests/MongoFramework.Tests/Infrastructure/EntityReaderTests.cs
  86. +0 −95 tests/MongoFramework.Tests/Infrastructure/EntityRelationships/CollectionMappingTests.cs
  87. +1 −1 ...oFramework.Tests/Infrastructure/EntityRelationships/EntityNavigationCollectionIntegrationTests.cs
  88. +11 −17 tests/MongoFramework.Tests/Infrastructure/EntityRelationships/EntityNavigationCollectionUnitTests.cs
  89. +1 −2 tests/MongoFramework.Tests/Infrastructure/EntityRelationships/SingleEntityIntegrationTests.cs
  90. +0 −129 tests/MongoFramework.Tests/Infrastructure/EntityRelationships/SingleEntityMappingTests.cs
  91. +6 −6 tests/MongoFramework.Tests/Infrastructure/EntityWriterTests.cs
  92. +0 −20 tests/MongoFramework.Tests/Infrastructure/Indexing/EntityIndexMapperTests.cs
  93. +7 −33 ...ests/Infrastructure/Indexing/{Processors/BasicIndexProcessorTests.cs → IndexModelBuilderTests.cs}
  94. +4 −7 tests/MongoFramework.Tests/Infrastructure/Linq/MongoFrameworkQueryableTests.cs
  95. +58 −0 tests/MongoFramework.Tests/Infrastructure/Mapping/EntityDefinitionExtensionTests.cs
  96. +0 −116 tests/MongoFramework.Tests/Infrastructure/Mapping/EntityMapperTests.cs
  97. +34 −0 tests/MongoFramework.Tests/Infrastructure/Mapping/EntityMappingTests.cs
  98. +20 −0 tests/MongoFramework.Tests/Infrastructure/Mapping/MappingTestBase.cs
  99. +6 −9 ...rastructure/Mapping/Processors/{BsonKnowTypesProcessorTests.cs → BsonKnownTypesProcessorTests.cs}
  100. +55 −0 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/CollectionNameProcessorTests.cs
  101. +21 −20 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/EntityIdProcessorTests.cs
  102. +224 −0 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/EntityRelationshipProcessorTests.cs
  103. +22 −12 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/ExtraElementsProcessorTests.cs
  104. +33 −15 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/HierarchyProcessorTests.cs
  105. +8 −19 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/MappedPropertiesProcessorTests.cs
  106. +10 −25 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/NestedPropertyProcessorTests.cs
  107. +14 −17 tests/MongoFramework.Tests/Infrastructure/Mapping/Processors/TypeDiscoveryProcessorTests.cs
  108. +0 −71 tests/MongoFramework.Tests/Infrastructure/Mutation/Mutators/IncrementNumberMutatorTests.cs
  109. +19 −16 ...Infrastructure/{EntityRelationships → Serialization}/EntityNavigationCollectionSerializerTests.cs
  110. +2 −26 ...s/MongoFramework.Tests/Infrastructure/{Mapping → }/Serialization/TypeDiscoveryIntegrationTests.cs
  111. +17 −14 ...MongoFramework.Tests/Infrastructure/{Mapping → }/Serialization/TypeDiscoverySerializationTests.cs
  112. +3 −3 tests/MongoFramework.Tests/Linq/LinqExtensionsTests.cs
  113. +1 −1 tests/MongoFramework.Tests/{Infrastructure → }/MongoDbUtilityTests.cs
  114. +1 −1 tests/MongoFramework.Tests/Profiling/MiniProfiler/MiniProfilerDiagnosticListenerTests.cs
  115. +11 −4 tests/MongoFramework.Tests/TestBase.cs
  116. +6 −1 tests/MongoFramework.Tests/TestConfiguration.cs
@@ -70,12 +70,8 @@ Populates the property with the current date/time on insert. _Note: The property

Populates the property with the current date/time on update. _Note: The property must be of type `DateTime`_

`[IncrementNumber(int incrementAmount = 1, bool onUpdateOnly = false)]`

Updates the value of a property by the defined increment amount on insert or update.

## Example
```
```csharp
using MongoFramework;
using System.ComponentModel.DataAnnotations;
@@ -88,16 +84,19 @@ public class MyEntity
public class MyContext : MongoDbContext
{
public MyContext() : base("MyContext") { }
public MyContext(IMongoDbConnection connection) : base(connection) { }
public MongoDbSet<MyEntity> MyEntities { get; set; }
public MongoDbSet<MyOtherEntity> MyOtherEntities { get; set; }
}
using (var myContext = new MyContext())
...
var connection = MongoDbConnection.FromConnectionString("YOUR_CONNECTION_STRING");
using (var myContext = new MyContext(connection))
{
var myEntity = myContext.MyEntities.Where(myEntity => myEntity.Name == "James").FirstOrDefault();
myEntity.Address = "123 SomeAddress Road, SomeSuburb";
myContext.SaveChanges();
await myContext.SaveChangesAsync();
}
```
@@ -7,6 +7,7 @@
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoFramework.Infrastructure;
using MongoFramework.Infrastructure.Diagnostics;
using StackExchange.Profiling;

namespace MongoFramework.Profiling.MiniProfiler
@@ -1,12 +1,13 @@
using System;
using System.Reflection;
using MongoFramework.Infrastructure.Mapping;

namespace MongoFramework.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class CreatedDateAttribute : MutatePropertyAttribute
{
public override void OnInsert(object target, PropertyInfo property)
public override void OnInsert(object target, IEntityProperty property)
{
if (property.PropertyType != typeof(DateTime))
{

This file was deleted.

Oops, something went wrong.
@@ -1,10 +1,9 @@
using MongoFramework.Infrastructure.Indexing;
using System;
using System;

namespace MongoFramework.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class IndexAttribute : Attribute, IEntityIndex
public class IndexAttribute : Attribute
{
public string Name { get; private set; }
public bool IsUnique { get; set; }
@@ -1,12 +1,13 @@
using System;
using System.Reflection;
using MongoFramework.Infrastructure.Mapping;

namespace MongoFramework.Attributes
{
public abstract class MutatePropertyAttribute : Attribute
{
public virtual void OnInsert(object target, PropertyInfo property) { }
public virtual void OnUpdate(object target, PropertyInfo property) { }
public virtual void OnSelect(object target, PropertyInfo property) { }
public virtual void OnInsert(object target, IEntityProperty property) { }
public virtual void OnUpdate(object target, IEntityProperty property) { }
public virtual void OnSelect(object target, IEntityProperty property) { }
}
}
@@ -1,12 +1,13 @@
using System;
using System.Reflection;
using MongoFramework.Infrastructure.Mapping;

namespace MongoFramework.Attributes
{
[AttributeUsage(AttributeTargets.Property)]
public class UpdatedDateAttribute : CreatedDateAttribute
{
public override void OnUpdate(object target, PropertyInfo property)
public override void OnUpdate(object target, IEntityProperty property)
{
if (property.PropertyType != typeof(DateTime))
{
@@ -1,15 +1,13 @@
using System;
using MongoDB.Driver;
using MongoFramework.Infrastructure;
using MongoFramework.Infrastructure.Indexing;
using MongoFramework.Infrastructure.Mapping;

namespace MongoFramework
{
public interface IMongoDbConnection : IEntityMapperFactory, IEntityIndexMapperFactory, IDisposable
public interface IMongoDbConnection : IDisposable
{
IMongoClient Client { get; }
IMongoDatabase GetDatabase();
IDiagnosticListener DiagnosticListener { get; }
IDiagnosticListener DiagnosticListener { set; get; }
}
}
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Text;
using MongoDB.Driver;
using MongoFramework.Infrastructure.DefinitionHelpers;

namespace MongoFramework.Infrastructure.Commands
{
@@ -5,6 +5,7 @@
using System;
using System.Linq;
using System.Linq.Expressions;
using MongoFramework.Infrastructure.Internal;

namespace MongoFramework.Infrastructure.DefinitionHelpers
{
@@ -3,7 +3,7 @@
using MongoDB.Driver;
using MongoFramework.Infrastructure.Linq;

namespace MongoFramework.Infrastructure
namespace MongoFramework.Infrastructure.Diagnostics
{
public abstract class DiagnosticCommand
{
@@ -1,6 +1,6 @@
using System;

namespace MongoFramework.Infrastructure
namespace MongoFramework.Infrastructure.Diagnostics
{
public class NoOpDiagnosticListener : IDiagnosticListener
{
@@ -1,24 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using MongoFramework.Infrastructure.Mapping;

namespace MongoFramework.Infrastructure
{
public class EntityBucketCollection<TGroup, TSubEntity> where TGroup : class
{
private Dictionary<TGroup, List<TSubEntity>> SubEntityStaging { get; }
private IEntityReader<EntityBucket<TGroup, TSubEntity>> EntityReader { get; }
private IEntityMapper EntityMapper { get; }

public int BucketSize { get; }

public EntityBucketCollection(IEntityReader<EntityBucket<TGroup, TSubEntity>> entityReader, int bucketSize, IEntityMapper entityMapper)
public EntityBucketCollection(IEntityReader<EntityBucket<TGroup, TSubEntity>> entityReader, int bucketSize)
{
SubEntityStaging = new Dictionary<TGroup, List<TSubEntity>>(new ShallowPropertyEqualityComparer<TGroup>());
EntityReader = entityReader;
BucketSize = bucketSize;
EntityMapper = entityMapper;
}

public void AddEntity(TGroup group, TSubEntity entity)
@@ -35,7 +32,7 @@ public void AddEntity(TGroup group, TSubEntity entity)

public IEntityCollection<EntityBucket<TGroup, TSubEntity>> AsEntityCollection()
{
var entityCollection = new EntityCollection<EntityBucket<TGroup, TSubEntity>>(EntityMapper);
var entityCollection = new EntityCollection<EntityBucket<TGroup, TSubEntity>>();

foreach (var grouping in SubEntityStaging)
{
@@ -1,12 +1,9 @@
using System.Linq;
using MongoFramework.Infrastructure.Mapping;

namespace MongoFramework.Infrastructure
{
public class EntityChangeTracker<TEntity> : EntityCollection<TEntity>, IEntityChangeTracker<TEntity> where TEntity : class
{
public EntityChangeTracker(IEntityMapper entityMapper) : base(entityMapper) { }

public void DetectChanges()
{
var entries = Entries.Where(e => e.State == EntityEntryState.NoChanges || e.State == EntityEntryState.Updated);
@@ -10,11 +10,11 @@ public class EntityCollection<TEntity> : IEntityCollection<TEntity> where TEntit
{
protected List<EntityEntry<TEntity>> Entries { get; } = new List<EntityEntry<TEntity>>();

private IEntityMapper EntityMapper { get; }
private IEntityDefinition EntityDefinition { get; }

public EntityCollection(IEntityMapper entityMapper)
public EntityCollection()
{
EntityMapper = entityMapper;
EntityDefinition = EntityMapping.GetOrCreateDefinition(typeof(TEntity));
}

public int Count => Entries.Count;
@@ -23,8 +23,8 @@ public EntityCollection(IEntityMapper entityMapper)

public EntityEntry<TEntity> GetEntry(TEntity entity)
{
var entityId = EntityMapper.GetIdValue(entity);
var defaultIdValue = EntityMapper.GetDefaultId();
var entityId = EntityDefinition.GetIdValue(entity);
var defaultIdValue = EntityDefinition.GetDefaultId();

foreach (var entry in Entries)
{
@@ -34,7 +34,7 @@ public EntityEntry<TEntity> GetEntry(TEntity entity)
}
else
{
var entryEntityId = EntityMapper.GetIdValue(entry.Entity);
var entryEntityId = EntityDefinition.GetIdValue(entry.Entity);
if (!Equals(entryEntityId, defaultIdValue) && entryEntityId.Equals(entityId))
{
return entry;
@@ -89,8 +89,16 @@ public void Clear()

public void Add(TEntity item)
{
//TODO: Check the ID value is a default value - if not, mark it as non-changed
Update(item, EntityEntryState.Added);
var defaultId = EntityDefinition.GetDefaultId();
var entityId = EntityDefinition.GetIdValue(item);
if (Equals(entityId, defaultId))
{
Update(item, EntityEntryState.Added);
}
else
{
Update(item, EntityEntryState.NoChanges);
}
}

public bool Contains(TEntity item)
@@ -5,28 +5,28 @@
using System.Collections.Generic;
using System.Linq;

namespace MongoFramework.Infrastructure.EntityRelationships
namespace MongoFramework.Infrastructure
{
public class EntityNavigationCollection<TEntity> : EntityCollection<TEntity>, IEntityNavigationCollection<TEntity> where TEntity : class
{
private IMongoDbConnection Connection { get; set; }
private IEntityMapper EntityMapper { get; }
private IEntityPropertyMap ForeignPropertyMap { get; }
private HashSet<object> UnloadedIds { get; } = new HashSet<object>();

public string ForeignKey { get; }
public IEntityProperty ForeignProperty { get; }

public new int Count => LoadedCount + UnloadedCount;

public int LoadedCount => Entries.Count;
public int UnloadedCount => UnloadedIds.Count;

public EntityNavigationCollection(string foreignKey, IMongoDbConnection connection) : base(connection?.GetEntityMapper(typeof(TEntity)))
public EntityNavigationCollection(IEntityProperty foreignProperty) : base()
{
ForeignKey = foreignKey ?? throw new ArgumentNullException(nameof(foreignKey));
Connection = connection ?? throw new ArgumentNullException(nameof(connection));
EntityMapper = connection.GetEntityMapper(typeof(TEntity));
ForeignPropertyMap = EntityMapper.GetEntityMapping().Where(m => m.Property.Name == foreignKey).FirstOrDefault();
ForeignProperty = foreignProperty ?? throw new ArgumentNullException(nameof(foreignProperty));
}

public void SetConnection(IMongoDbConnection connection)
{
Connection = connection;
}

public void AddForeignId(object foreignId)
@@ -37,14 +37,13 @@ public void AddForeignId(object foreignId)
}

//Check the EntityId matches the known type for TEntity
if (!ForeignPropertyMap.PropertyType.Equals(foreignId.GetType()))
if (!ForeignProperty.PropertyType.Equals(foreignId.GetType()))
{
throw new InvalidOperationException($"Type mismatch for foreign key. {foreignId.GetType()} specified however expected type {ForeignPropertyMap.PropertyType}");
throw new InvalidOperationException($"Type mismatch for foreign key. {foreignId.GetType()} specified however expected type {ForeignProperty.PropertyType}");
}

//Check the entity isn't already loaded
var foreignProperty = ForeignPropertyMap.Property;
if (!Entries.Any(e => Equals(foreignId, foreignProperty.GetValue(e.Entity))))
if (!Entries.Any(e => Equals(foreignId, ForeignProperty.GetValue(e.Entity))))
{
UnloadedIds.Add(foreignId);
}
@@ -66,7 +65,7 @@ public void LoadEntities()
}

var dbEntityReader = new EntityReader<TEntity>(Connection);
var entities = dbEntityReader.AsQueryable().WherePropertyMatches(ForeignKey, ForeignPropertyMap.PropertyType, UnloadedIds);
var entities = dbEntityReader.AsQueryable().WherePropertyMatches(ForeignProperty, UnloadedIds);

foreach (var entity in entities)
{
@@ -78,7 +77,7 @@ public void LoadEntities()

public IEnumerable<object> GetForeignIds()
{
var loadedEntityIds = Entries.Select(e => ForeignPropertyMap.Property.GetValue(e.Entity));
var loadedEntityIds = Entries.Select(e => ForeignProperty.GetValue(e.Entity));
return loadedEntityIds.Concat(UnloadedIds);
}

@@ -98,7 +97,7 @@ public new IEnumerator<TEntity> GetEnumerator()
if (UnloadedIds.Any())
{
var dbEntityReader = new EntityReader<TEntity>(Connection);
var unloadedEntities = dbEntityReader.AsQueryable().WherePropertyMatches(ForeignKey, ForeignPropertyMap.PropertyType, UnloadedIds);
var unloadedEntities = dbEntityReader.AsQueryable().WherePropertyMatches(ForeignProperty, UnloadedIds);

using (var unloadedEnumerator = unloadedEntities.GetEnumerator())
{
@@ -110,7 +109,7 @@ public new IEnumerator<TEntity> GetEnumerator()
Update(loadedEntity, EntityEntryState.NoChanges);

//Remove from unloaded entity collection
var foreignId = ForeignPropertyMap.Property.GetValue(loadedEntity);
var foreignId = ForeignProperty.GetValue(loadedEntity);
UnloadedIds.Remove(foreignId);

yield return loadedEntity;
Oops, something went wrong.

0 comments on commit c6ebe58

Please sign in to comment.
You can’t perform that action at this time.