コード例 #1
0
        public string DesignShemaTypeToCSharp(StoreProperty p)
        {
            if (p.Pk && p.Type == "int")
            {
                //return "long";
                return("int");
            }

            string result;

            if (p.Fk)
            {
                result = DesignSchemaTypesMap[p.ForeignKeys.First().Type];
            }
            else
            {
                if (DesignSchemaTypesMap.ContainsKey(p.Type))
                {
                    result = DesignSchemaTypesMap[p.Type];
                }
                else
                {
                    result = p.Type;
                }
            }

            if (result != "string" && p.Nullable)
            {
                result = result + "?";
            }

            return(result);
        }
        public StoreSchema ReadSchema(IStoreSchemaReaderParameters parameters)
        {
            var dr = parameters as EntityFrameworkStoreSchemaReaderParameters;

            if (dr == null)
            {
                throw new Exception($"EntityFrameworkStoreSchemaReader expects EntityFrameworkStoreSchemaReaderParameters.");
            }

            var schema = new StoreSchema {
                Definitions = new Dictionary <string, StoreDefinition>(), DbContextName = dr.DbContextType.FullName
            };

            using (var db = GetDbContext(dr.DbContextType))
            {
                var entities = db.Model.GetEntityTypes();

                foreach (var entityMetadata in entities)
                {
                    var def = new StoreDefinition {
                        Properties = new Dictionary <string, StoreProperty>()
                    };
                    def.Name = entityMetadata.ClrType.Name;
                    schema.Definitions.Add(def.Name, def);
                    var props = entityMetadata.GetProperties().ToList();

                    for (int i = 0; i < props.Count; i++)
                    {
                        var prop = props[i];

                        var storeProp = new StoreProperty
                        {
                            Name          = prop.Name,
                            Order         = i,
                            Type          = GetTypeString(prop.ClrType),
                            Pk            = prop.IsPrimaryKey(),
                            Fk            = prop.IsForeignKey(),
                            MaxLength     = prop.GetMaxLength(),
                            AutoIncrement = prop.ValueGenerated == ValueGenerated.OnAdd
                        };

                        if (prop.IsForeignKey())
                        {
                            var fks = prop.GetContainingForeignKeys();
                            storeProp.ForeignKeys = prop.GetContainingForeignKeys().Select(f => new StoreForeignKey
                            {
                                DefinitionName         = f.PrincipalEntityType.ClrType.Name,
                                PropertyName           = f.PrincipalKey.Properties.First().Name,
                                CompositePropertyNames = f.PrincipalKey.Properties.Select(p => p.Name).ToList()
                            }).ToList();
                        }

                        def.Properties.Add(storeProp.Name, storeProp);
                    }
                }
            }

            return(schema);
        }
コード例 #3
0
        private string GetPropertyDataType(StoreProperty p)
        {
            if (p.Type == "reference" && p.Fk)
            {
                return(p.ForeignKeys[0].Type);
            }

            return(p.Type);
        }
コード例 #4
0
        private static string GetDesignForeignKey(StoreProperty c)
        {
            if (c.ForeignKeys.Any())
            {
                var fk = c.ForeignKeys.First();
                return($"{fk.DefinitionName}.{fk.PropertyName}");
            }

            return(null);
        }
コード例 #5
0
        public static StoreProperty ToStorePropertyMin(DesignColumn c)
        {
            var result = new StoreProperty
            {
                Name          = c.Name,
                Type          = c.Type,
                Pk            = c.Pk,
                Fk            = !string.IsNullOrWhiteSpace(c.Reference),
                Nullable      = c.Nullable,
                AutoIncrement = c.Pk,
            };

            return(result);
        }
コード例 #6
0
ファイル: JobHelper.cs プロジェクト: umialpha/Telepathy
        /// <summary>
        /// Get value from a store property
        /// </summary>
        /// <param name="prop">indicate the store property</param>
        /// <param name="propId">the expected property Id</param>
        /// <param name="defaultValue">default value</param>
        /// <param name="callerName">caller name of this method, such as [JobMonitorEntry.GetMinAndMax]. it is only used in the log</param>
        /// <returns>return property value if it exists, otherwise return default value</returns>
        internal static object GetStorePropertyValue(StoreProperty prop, PropertyId propId, object defaultValue, string callerName)
        {
            if (prop.Id == propId && prop.Value != null)
            {
                return(prop.Value);
            }
            else
            {
                TraceHelper.TraceEvent(
                    TraceEventType.Error,
                    "{0} Can't get valid value from store property {1}.", callerName, propId.Name);

                return(defaultValue);
            }
        }
コード例 #7
0
        public static StoreProperty ToStoreProperty(DesignSchema schema, DesignTable t, DesignColumn c)
        {
            var i = t.Columns.IndexOf(c);

            var result = new StoreProperty
            {
                Name          = c.Name,
                Type          = c.Type,
                Pk            = c.Pk,
                Fk            = !string.IsNullOrWhiteSpace(c.Reference),
                Nullable      = c.Nullable,
                AutoIncrement = c.Pk,
                ForeignKeys   = GetForeignKeysForColumn(schema, t, c),
                Order         = i++
            };

            return(result);
        }
コード例 #8
0
 public QuerySelectProperty(QueryFromTable fromTable, StoreProperty source)
 {
     FromTable     = fromTable;
     StoreProperty = source;
 }
コード例 #9
0
 set => SetValue(StoreProperty, value);
コード例 #10
0
 set { SetValue(StoreProperty, value); OnPropertyChanged(); }
コード例 #11
0
 public EvalueStorageNG()
 {
     // Just init list
     Evalues   = new List <Evalue>();
     PropStore = new StoreProperty <Evalue>();
 }
コード例 #12
0
 public QueryFromProperty(QuerySelectProperty source)
 {
     OriginalStoreProperty = new SubQueryStoreProperty(source);
 }
コード例 #13
0
 public QueryFromProperty(StoreProperty source)
 {
     OriginalStoreProperty = source;
 }
コード例 #14
0
 public QueryFromProperty(StoreProperty source)
 {
     StoreProperty = source;
 }