-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
60 lines (54 loc) · 1.96 KB
/
Program.cs
File metadata and controls
60 lines (54 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using Microsoft.SqlServer.Management.Smo;
namespace CodeGenerator
{
class Program
{
static void Main(string[] args)
{
string templete = File.ReadAllText("templete2.txt");
var dbName = "AdventureWorks2012";
var dbInfo = new DataBasesInfo();
var tables = dbInfo.GetTables(dbName);
var generator = new Generator();
generator.Templete = templete;
var code = string.Empty;
foreach (var table in tables)
{
var em = new EntityModel();
em.NameSpace = "DAL";
em.Name = table.Name;
em.Comments = new string[] { "author:YGJ" };
var fields = new List<EntityField>();
//var columns = dbInfo.GetTableClomns(dbName, table);
foreach (Column col in table.Columns)
{
var ef = new EntityField();
ef.Name = col.Name;
ef.DataType = col.DataType.ToString();
ef.DbNullAbel = col.Nullable;
ef.Description = col.ExtendedProperties.Contains("MS_Description") ? col.ExtendedProperties["MS_Description"].Value.ToString() : string.Empty;
fields.Add(ef);
}
em.Fields = fields;
try
{
code = generator.GeneratorCode(em);
string path = string.Format(@"D:\ModelTest\{0}.cs", em.Name);
File.WriteAllText(path, code, Encoding.Default);
Console.WriteLine(em.Name);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
}