Exemplo n.º 1
0
 /// <summary>Instructs to map a given predicate to a given <typeparamref name="T" />.</summary>
 /// <typeparam name="T">Type of the entity owning the property to be mapped.</typeparam>
 /// <param name="e">Event arguments.</param>
 /// <param name="mappingsBuilder">Mappings builder.</param>
 public static void OfEntity <T>(this UnmappedPropertyEventArgs e, Action <IExplicitMappingsBuilder <T> > mappingsBuilder) where T : IEntity
 {
     if (e != null)
     {
         e.PropertyMapping = e.EntityContext.BuildExplicitMappings(mappingsBuilder, e.Statement.Subject, true);
     }
 }
Exemplo n.º 2
0
        internal virtual void InitializeInternal(Entity entity, IEnumerable <Statement> statements, EntityInitializationContext context, Action <Statement> onIteration = null)
        {
            if (onIteration == null)
            {
                onIteration = _ => { };
            }

            foreach (var statement in statements)
            {
                onIteration(statement);
                if (!statement.IsRelatedTo(entity))
                {
                    context.EntityStatements.EnsureKey(statement.Subject).Add(statement);
                    continue;
                }

                if (statement.IsTypeAssertion())
                {
                    var entityMapping = Mappings.FindEntityMappingFor(entity, statement.Object, statement.Graph);
                    if (entityMapping != null)
                    {
                        entity.CastedTypes.Add(entityMapping.Type);
                    }

                    continue;
                }

                var propertyMapping = Mappings.FindPropertyMappingFor(entity, statement.Predicate, statement.Graph);
                if ((propertyMapping == null) && (UnmappedPropertyEncountered != null))
                {
                    var e = new UnmappedPropertyEventArgs(this, statement);
                    UnmappedPropertyEncountered(this, e);
                    propertyMapping = e.PropertyMapping;
                }

                if ((propertyMapping == null) || (!statement.Matches(propertyMapping.Graph)))
                {
                    continue;
                }

                //// TODO: Develop a dictionary statements handling.
                var collectionMapping = propertyMapping as ICollectionMapping;
                if (collectionMapping?.StoreAs == CollectionStorageModel.LinkedList)
                {
                    context.LinkedLists.EnsureKey(entity.Iri)[statement.Object] = collectionMapping;
                    continue;
                }

                entity.SetProperty(statement, propertyMapping, context);
            }

            entity.InitializeLists(context);
            entity.IsInitialized = true;
            InitializeChildEntities(context);
        }