[英]Get the stored procedure schema
I'm trying to write a framework to generate entities from an existing database. 我正在尝试编写一个框架来从现有数据库生成实体。
I've already implemented all the code to generate the entities from the tables and it works well. 我已经实现了所有代码以从表中生成实体,并且效果很好。 Now I'm looking for a solution to retrieve all the information I need to generate a stored procedure entity. 现在,我正在寻找一种解决方案来检索生成存储过程实体所需的所有信息。
This is the code I use to get the stored procedure parameters 这是我用来获取存储过程参数的代码
public static List<StoredProcedureParameter> GetStoredProceduresParameters(SqlConnection connection, string storedProcedureName, bool closeConnection = true)
{
var query = @"select Parameter_Name, Data_Type, CHARACTER_MAXIMUM_LENGTH
from information_schema.parameters
where specific_name = @StoredProcedureName";
var storedProcedures = new List<string>();
SqlCommand command = new SqlCommand(query, connection);
command.Parameters.Add(new SqlParameter("StoredProcedureName", storedProcedureName));
DataTable dataTable = new DataTable();
using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command))
{
dataAdapter.Fill(dataTable);
}
if (closeConnection)
{
connection.Close();
}
return DataTableMapper.ReadDataTableList<StoredProcedureParameter>(dataTable);
}
Now I have to retrieve the result set schema, but I can't find the right way to accomplish this task. 现在,我必须检索结果集架构,但是找不到正确的方法来完成此任务。 Any suggestions? 有什么建议么?
NOTE : all the stored procedures will always return just one possible schema, so any one stored procedure will always correspond to exactly one entity. 注意 :所有存储过程将始终仅返回一个可能的模式,因此任何一个存储过程将始终仅对应于一个实体。
Hi SimoneL: There are frameworks to do just that for you, NHibernate or EF (Entity Framework) from Microsoft, do they not answer all your needs? 嗨,SimoneL:可以使用Microsoft的NHibernate或EF(实体框架)来为您做到这一点的框架,它们不能满足您的所有需求吗?
EF getting Started: http://msdn.microsoft.com/en-gb/data/ee712907#getstarted EF入门: http : //msdn.microsoft.com/en-gb/data/ee712907#getstarted
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.