public ExcelDatabaseParser(string pathToFolder, T context, ContextDefinition contextDef) { _pathToFolder = pathToFolder; _context = context; _contextDef = contextDef; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); }
public ContextDefinition ReadContext() { var contextDef = new ContextDefinition(); _context.Model.GetEntityTypes().ToList().ForEach(entity => { var newEntity = new EntityDefinition { EntityName = entity.Name, EntityClrType = entity.ClrType }; // Get its DbSet var allDbSets = _context.GetType().GetProperties().Where(p => p.PropertyType.FullName.Contains("DbSet")).ToList(); var dbSet = allDbSets.SingleOrDefault(p => p.PropertyType.GenericTypeArguments.Length == 1 && p.PropertyType.GenericTypeArguments[0].FullName == entity.Name); if (dbSet != null) { newEntity.DbSetName = dbSet.Name; } var tableName = entity.ClrType.Name; var allAnnotations = entity.GetAnnotations(); var tableAttribute = entity.ClrType.GetTypeInfo().GetCustomAttribute <TableAttribute>(true); if (tableAttribute != null) { tableName = tableAttribute.Name; } else if (newEntity.DbSetName != null) { tableName = newEntity.DbSetName; } newEntity.FieldMapping = HandleFieldMapping(entity); contextDef.AllTables.Add(tableName, newEntity); }); return(contextDef); }