[英]Best practice for data access to third-party applications using .NET Entity Framework
我正在为现有的第三方应用程序构建自定义项。 我的代码在同一.NET应用程序池中运行,并且与第三方应用程序在同一服务器上。
我无权访问其数据模型,也没有API。 我一直在编写SQL查询并为自定义开发WCF服务。 这行得通,但感觉很“糟糕”。 下面是一个示例:
public DLPDetail GetEventDetail(int id)
{
DLPDetail detail = new DLPDetail();
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["DLP"].ToString());
con.Open();
SqlCommand command = new SqlCommand("SELECT compound_path, FILE_MATCH_ID FROM E_ABSTRACT_FILE_MATCH WHERE EVENT_ID = '" + id + "'", con);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
detail.Name = reader.GetString(0);
detail.FileMatchId = reader.GetInt64(1).ToString();
}
return detail;
}
我想知道是否有更好的方法可以使用诸如实体框架之类的东西。 有什么想法吗?
一些建议:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.