1

我有实体框架 edmx 的连接字符串,它通常是带有元数据的 EF 连接字符串。

现在我正在实现 mvc-mini-profiler 并在下面编写方法来创建上下文。我现在只使用 sql 连接字符串部分,不再使用 EF 连接字符串。

现在它可以工作了,但我很好奇它是如何获取元数据(.csdl,.ssdl 地址)的,如果它现在可以找到,那么为什么'new 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>();
    }
4

1 回答 1

2

它在没有元数据的情况下工作的原因是CreateObjectContext扩展方法会在创建上下文时添加这些元数据。它使用通配符:res://*/来获取元数据。你可以在这里查看实现。

于 2011-07-17T13:47:39.070 回答