Skip to content

Commit

Permalink
Update Program.cs
Browse files Browse the repository at this point in the history
Added alternative schema/database name lookup
  • Loading branch information
DXSdata committed Mar 12, 2019
1 parent 332df61 commit 9393705
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions DotnetEfDbcontextConverter/Program.cs
Expand Up @@ -36,9 +36,18 @@ static void Main(string[] args)
//Get original schema name
var schemaPosition = content.IndexOf("entity.ToTable(");
var origSchema = content.Substring(schemaPosition, 50);
origSchema = origSchema.Split(",")[1].Trim().Trim('"');
var schemaEndPosition = origSchema.IndexOf('"');
origSchema = origSchema.Substring(0, schemaEndPosition);
try
{
origSchema = origSchema.Split(",")[1].Trim().Trim('"');
var schemaEndPosition = origSchema.IndexOf('"');
origSchema = origSchema.Substring(0, schemaEndPosition);
}
catch(IndexOutOfRangeException) //As an alternative method, use database name from connection string
{
schemaPosition = content.IndexOf("database=");
origSchema = content.Substring(schemaPosition);
origSchema = origSchema.Split(";", 2)[0].Trim().Replace("database=","").Replace("\"", "").Replace(")", "");
}


//Insert static schema variable declaration
Expand Down

0 comments on commit 9393705

Please sign in to comment.