Exemple #1
0
        internal virtual EntityType AddEntityType([NotNull] Microsoft.EntityFrameworkCore.Metadata.IEntityType entityType)
        {
            _efEntityTypes.Add(entityType.Name, new EntityType(entityType, this));
            _clrTypeNameMap.Add(entityType.ClrType, entityType.Name);

            return(_efEntityTypes[entityType.Name]);
        }
        public EntityType(Microsoft.EntityFrameworkCore.Metadata.IEntityType entityType, Model model)
        {
            ClrType = entityType.ClrType;
            Model   = model;
            Name    = entityType.Name;

            SetProperties(entityType.GetProperties());
            SetPrimaryKey(entityType.FindPrimaryKey());
        }
Exemple #3
0
        public static string GetTableName <T>(DbContext context) where T : class
        {
            // We need dbcontext to access the models
            Microsoft.EntityFrameworkCore.Metadata.IModel models = context.Model;

            // Get all the entity types information
            IEnumerable <Microsoft.EntityFrameworkCore.Metadata.IEntityType> entityTypes = models.GetEntityTypes();

            // T is Name of class
            Microsoft.EntityFrameworkCore.Metadata.IEntityType entityTypeOfT = entityTypes.First(t => t.ClrType == typeof(T));

            IAnnotation tableNameAnnotation = entityTypeOfT.GetAnnotation("Relational:TableName");
            string      TableName           = tableNameAnnotation.Value.ToString();

            return(TableName);
        }
Exemple #4
0
 public override ValueGenerator Create(Microsoft.EntityFrameworkCore.Metadata.IProperty property, Microsoft.EntityFrameworkCore.Metadata.IEntityType entityType)
 {
     return(base.Create(property, entityType));
 }
Exemple #5
0
 public static string Tabla <T>(this T col, DbContext db) where T : Type
 {
     //ProtoDBContext db = new ProtoDBContext();
     Microsoft.EntityFrameworkCore.Metadata.IEntityType entityType = db.Model.FindEntityType((col));
     return(entityType.GetTableName());
 }