📜  raq query ef core - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:48.954000             🧑  作者: Mango

代码示例1
public static class Helper
{
    public static List RawSqlQuery(string query, Func map)
    {
        using (var context = new DbContext())
        {
            using (var command = context.Database.GetDbConnection().CreateCommand())
            {
                command.CommandText = query;
                command.CommandType = CommandType.Text;

                context.Database.OpenConnection();

                using (var result = command.ExecuteReader())
                {
                    var entities = new List();

                    while (result.Read())
                    {
                        entities.Add(map(result));
                    }

                    return entities;
                }
            }
        }
    }