Esempio n. 1
0
 /// <summary>
 /// Use the "CreateEntityInfo" method on the persis manager if you want to create EntityInfo yourself.
 /// The default ctor is provided for serealization and testing only
 /// </summary>
 internal EntityInfo(EntitySetInfo entitySetInfo, object entity, EntityState entityState, AutoGeneratedKey autoGeneratedKey, Dictionary <string, object> originalValuesMap, Dictionary <string, object> unmappedValuesMap)
 {
     EntitySetInfo     = entitySetInfo;
     Type              = entitySetInfo.ClrType;
     Entity            = entity;
     EntityState       = entityState;
     AutoGeneratedKey  = autoGeneratedKey;
     OriginalValuesMap = originalValuesMap ?? new Dictionary <string, object>();
     UnmappedValuesMap = unmappedValuesMap ?? new Dictionary <string, object>();
 }
Esempio n. 2
0
        /// <summary>
        /// Returns a description of each entity in the context, sorted according to
        /// the order the entities should be saved
        /// </summary>
        public static List <EntitySetInfo> GetEntitySetsInfo(T ctx)
        {
            var model = GetModel(ctx);

            var entityTypes = model.GetEntityTypes();

            var typesAndDependencies = entityTypes.OrderBy(et => et.Name)
                                       .Select(et =>
            {
                var dependencies        = GetTypesEntityDependsOn(et).Select(e => e.Name);
                var depenednciesHashset = new HashSet <string>(dependencies);

                return(et, dependencies);
            }).ToList();

            var entitiesInfo = new List <EntitySetInfo>();
            var alreadySaved = new HashSet <string>();

            /// Will holt or throw since we are removing an item each time or throwing if we did not
            /// find an item
            while (typesAndDependencies.Count > 0)
            {
                var nextToSave = typesAndDependencies.First((t) =>
                {
                    return(t.dependencies.Except(alreadySaved).Count() == 0);
                });

                var jsName = JsTypeNameFromType(nextToSave.et.ClrType);

                alreadySaved.Add(nextToSave.et.Name);
                typesAndDependencies.Remove(nextToSave);
                var entitySetInfo = new EntitySetInfo(jsName, nextToSave.et.ClrType, nextToSave.et);
                entitiesInfo.Add(entitySetInfo);
            }

            return(entitiesInfo);
        }