我有实体框架edmx的连接字符串,这是通常的带有元数据的EF连接字符串。
现在我正在实现mvc-mini-profiler并在下面编写方法来创建上下文。我现在只使用sql连接字符串部分,不再使用EF连接字符串。
现在它有效,但我很好奇如何获取元数据(.csdl,.ssdl地址),如果它现在可以找到那么为什么'新的Context()'需要元数据
public static T GetProfiledContext<T>() where T : ObjectContext
{
// create connection
var sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString);
// wrap the connection with a profiling connection that tracks timings
var profiledDbConnection = MvcMiniProfiler.Data.ProfiledDbConnection.Get(sqlConnection, MiniProfiler.Current);
// create context
return profiledDbConnection.CreateObjectContext<T>();
}
答案 0 :(得分:2)
没有元数据的原因是CreateObjectContext
扩展方法会在创建上下文时添加这些元数据。它使用通配符:res://*/
来获取元数据。您可以查看实施here。