开发者

Why connectionstring without metadata works?

I had connection strings for entity framework edmx, which is usual EF connection string with metadata.

Now i am implementing mvc-mini-profiler and wrote method below to create context. I am using just sql connection string part now, no longer using EF connection string.

Now it works but i am curious how it is getting metadata(.csdl, .ssdl address), If it can find now then why 'new Context()' need metadata

public static T GetProfiledContext<T>() where T : ObjectContext
    {
        // create c开发者_如何学Goonnection
        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>();
    }


The reason why it works without metadata is that CreateObjectContext extension method will add these metadata when creating the context. It uses wildcards: res://*/ to get metadata. You can check the implementation here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜