나는 클래스 생성 (테이블을위한 하나의 클래스 - 상속 등은 지금 고려하지 말아야한다 ...)으로 놀고있다. 그래서 나는 here Reflection.Emit 코드에서 뻔뻔스럽게 복사했습니다. 지정된 데이터베이스의 테이블 당 생성되도록 다시 작성하고 프로젝트의 bin 폴더에 다음 일괄 처리 호출로 파일을 생성했습니다. /f "tokens = *"%% i in ('dir * .xsd/b')에 대해 for do "C : ₩ Program Files ₩ Microsoft SDKs ₩ Windows ₩ v6.0A ₩ bin ₩ xsd.exe"-c -l : C# -n : BusinessObjects % iReflection.Emit 및 xsd 파일을 사용하여 데이터베이스 테이블에서 클래스를 생성 할 때 예상되는 함정은 무엇입니까?
지금까지는 그렇게 좋았습니다. 이 아이디어는 새로운 db 버전이 도착하여 클래스를 재생성하고 "실제 프로젝트"(런타임 생성이 필요하지 않음)에서 복사하고 Intellisense를 즐기기를 원할 때마다 있습니다. 이러한 유형의 접근에서 느낄 수있는 함정, 어려움 및 문제점, 느슨하게 묘사 된 요구 사항에 대한 더 나은 제안은 무엇입니까? 당신은 (관계)를 사용하여 모든 문제를 얻을
using System;
using System.Collections.Generic;
using System.Text;
using log4net;
using log4net.Config;
using System.Data;
using System.Data.SqlClient;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
namespace GenerateAssemblies
{
class Program
{
private static readonly ILog logger =
LogManager.GetLogger (typeof (Program));
static void Main (string[] args)
{
DOMConfigurator.Configure(); //tis configures the logger
logger.Debug ("APP START");
DataTable dtTables = Program.GetTablesFromDb ("POC") ;
foreach (DataRow dr in dtTables.Rows)
{
string strTableName = dr[0].ToString() ;
CodeEmitGeneratingAssemblies.DllGenerator.WriteXmlAndTxtFileOutOfDataTableByName ( strTableName);
CodeEmitGeneratingAssemblies.DllGenerator.CreateAssembly (strTableName);
}
Console.WriteLine (" Should have now all the dll's ");
Console.ReadLine();
} //eof method
static DataTable GetTablesFromDb (string strDbName)
{
DataTable dt = new DataTable ("tables");
string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=" + strDbName + ";Data Source=ysg";
using (SqlConnection connection = new SqlConnection (connectionString))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = string.Format ("SELECT name from sys.tables");
connection.Open();
dt.Load (command.ExecuteReader (CommandBehavior.CloseConnection));
}
return dt;
} //eof method
} //eof class
namespace CodeEmitGeneratingAssemblies
{
public class DllGenerator
{
private static readonly ILog logger =
LogManager.GetLogger (typeof (DllGenerator));
public static void WriteXmlAndTxtFileOutOfDataTableByName (string strDataTableName)
{
DOMConfigurator.Configure(); //tis configures the logger
DataTable tableData = new DataTable (strDataTableName);
string connectionString = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=POC;Data Source=ysg";
using (SqlConnection connection = new SqlConnection (connectionString))
{
SqlCommand command = connection.CreateCommand();
command.CommandText = string.Format ("SELECT * FROM [" + strDataTableName + "]");
logger.Debug ("command.CommandText is " + command.CommandText);
connection.Open();
tableData.Load (command.ExecuteReader (CommandBehavior.CloseConnection));
}
tableData.WriteXml (strDataTableName + ".xml");
tableData.WriteXmlSchema (strDataTableName + ".xsd");
} //eof method
public static void CreateAssembly (string strDataTableName)
{
AppDomain currentDomain = Thread.GetDomain();
AssemblyName myAssemblyName = new AssemblyName ();
myAssemblyName.Name = strDataTableName;
AssemblyBuilder builder = currentDomain.DefineDynamicAssembly (
myAssemblyName,
AssemblyBuilderAccess.RunAndSave);
builder.AddResourceFile ("TableXml", strDataTableName + ".xml");
builder.AddResourceFile ("TableXsd", strDataTableName + ".xsd");
builder.Save (strDataTableName + ".dll");
}
} //eof class
} //eof namespace
} //eof namespace
... 내 문제가 실제로 DB 아직 내가 그것을 채택해야 존재한다는 것입니다 내가 당신과 동의 .. –