。net EF核心问题中的查询字符串sql句子

问题描述 投票:0回答:1

我是使用.Net Core EF的新手。

我的数据库表中有一个句子,我必须像(使用ado.net)那样执行:

using (var command = context.Database.GetDbConnection().CreateCommand())
{
    command.CommandText = "<<my sql sentence>>";
    context.Database.OpenConnection();
    using (var result = command.ExecuteReader())
    {
       ....
    }
}

我在here中找到此文档。

我的问题很简单:执行查询后是否需要关闭连接?我认为应该这样做(但我想),但我不知道是否有必要使用相同的EF行为并自动关闭。

c# .net entity-framework core
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.