Exemplo n.º 1
0
        private static void AddTableDescription(T context, System.Type entityType, string tableName)
        {
            string memberDescription = DescriptionInitializer <T> .GetMemberDescription(entityType);

            if (!string.IsNullOrEmpty(memberDescription))
            {
                Database arg_35_0 = context.Database;
                string   arg_35_1 = "IF EXISTS(SELECT 1 FROM syscolumns WHERE id = OBJECT_ID({1})) BEGIN IF EXISTS(SELECT 1 FROM ::fn_listextendedproperty (default,'schema',N'dbo', 'table', {1}, {2}, {3}) where name='MS_DESCRIPTION') BEGIN EXEC sp_updateextendedproperty N'MS_Description', {0}, 'SCHEMA', N'dbo', 'TABLE', {1}, {2}, {3} END ELSE BEGIN EXEC sp_addextendedproperty N'MS_Description', {0}, 'SCHEMA', N'dbo', 'TABLE', {1}, {2}, {3} END END";
                object[] array    = new object[4];
                array[0] = memberDescription;
                array[1] = tableName;
                arg_35_0.ExecuteSqlCommand(arg_35_1, array);
            }
        }
Exemplo n.º 2
0
        private static void AddColumnDescription(T context, System.Reflection.PropertyInfo property, string tableName)
        {
            string text = DescriptionInitializer <T> .GetMemberDescription(property) ?? DescriptionInitializer <T> .GetDisplayName(property);

            if (!string.IsNullOrEmpty(text))
            {
                context.Database.ExecuteSqlCommand("IF EXISTS(SELECT 1 FROM syscolumns WHERE id = OBJECT_ID({1}) AND NAME = {3}) BEGIN IF EXISTS(SELECT 1 FROM ::fn_listextendedproperty (default,'schema',N'dbo', 'table', {1}, {2}, {3}) where name='MS_DESCRIPTION') BEGIN EXEC sp_updateextendedproperty N'MS_Description', {0}, 'SCHEMA', N'dbo', 'TABLE', {1}, {2}, {3} END ELSE BEGIN EXEC sp_addextendedproperty N'MS_Description', {0}, 'SCHEMA', N'dbo', 'TABLE', {1}, {2}, {3} END END", new object[]
                {
                    text,
                    tableName,
                    "COLUMN",
                    DescriptionInitializer <T> .GetRealColumnName(property)
                });
            }
        }
Exemplo n.º 3
0
        public void InitializeDatabase(T context)
        {
            foreach (System.Reflection.PropertyInfo current in
                     from p in typeof(T).GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public)
                     where p.PropertyType.Name == typeof(DbSet).Name
                     select p)
            {
                System.Type type          = current.PropertyType.GetGenericArguments().Single <System.Type>();
                string      realTableName = DescriptionInitializer <T> .GetRealTableName(context, type);

                DescriptionInitializer <T> .AddTableDescription(context, type, realTableName);

                System.Reflection.PropertyInfo[] properties = type.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                for (int i = 0; i < properties.Length; i++)
                {
                    System.Reflection.PropertyInfo propertyInfo = properties[i];
                    if (!propertyInfo.IsDefined(typeof(NotMappedAttribute), false))
                    {
                        DescriptionInitializer <T> .AddColumnDescription(context, propertyInfo, realTableName);
                    }
                }
            }
        }