相关疑难解决方法(0)

实体框架6 - 定时查询

我正在使用Entity Framework 6,它是一个非常棒的数据库拦截器功能,用于记录从应用程序数据库发送的查询.但是,我正在努力为这些查询计时,我有一个长时间运行的查询,返回数十万到数百万行,因此需要大约6到15秒,具体取决于此查询将返回的数据量.实体框架返回一个SqlDataReader,因为我无法获得获取结果所需的确切时间.我想知道从查询发送到读取最后一行的时间的完整执行时间.有没有办法可以做到.

c# sql-server entity-framework entity-framework-6

14
推荐指数
1
解决办法
7154
查看次数

从 IDbCommandInterceptor 的实现获取 DbContext

我正在使用一个IDbCommandInterceptor实现:

\n\n
public class MyInterceptor : IDbCommandInterceptor\n{\n    public void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)\n    {\n        var context = interceptionContext.DbContexts.FirstOrDefault();\n    }\n\n    public void NonQueryExecuting(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)\n    {\n    }\n\n    public void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)\n    {\n    }\n\n    public void NonQueryExecuted(DbCommand command, DbCommandInterceptionContext<int> interceptionContext)\n    {\n    }\n\n    public void ReaderExecuted(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)\n    {\n    }\n\n    public void ScalarExecuted(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)\n    {\n    }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

以此注入:

\n\n
public class TestContext : System.Data.Entity.DbContext\n{\n    // \xe2\x80\xa6\n\n    public TestContext()\n        : base("TestConnectionString")\n    {\n        Database.SetInitializer<TestContext>(null);\n        DbInterception.Add(new MyInterceptor());\n    }\n}\n …
Run Code Online (Sandbox Code Playgroud)

c# entity-framework interceptor entity-framework-6

5
推荐指数
1
解决办法
3580
查看次数

使用C#实体框架在时态表中插入记录

我在Temporal table使用C#实体框架插入数据时遇到问题

表架构是

CREATE TABLE People( 
    PeopleID int PRIMARY KEY NOT NULL, 
    Name varchar(50) Null, 
    LastName varchar(100) NULL, 
    NickName varchar(25), 
    StartTime datetime2 GENERATED ALWAYS AS ROW START NOT NULL, 
    EndTime datetime2 GENERATED ALWAYS AS ROW END NOT NULL, 
    PERIOD FOR SYSTEM_TIME (StartTime,EndTime) 
) WITH (SYSTEM_VERSIONING = ON(HISTORY_TABLE = dbo.PeopleHistory));
Run Code Online (Sandbox Code Playgroud)

我创建了一个EDMX asusal,并尝试使用以下C#代码插入一条记录

using (var db = new DevDBEntities()) {
    People1 peo = new People1() {
        PeopleID = 1,
        Name = "Emma",
        LastName = "Watson",
        NickName = "ICE"
    };

    db.Peoples.Add(peo); …
Run Code Online (Sandbox Code Playgroud)

c# sql-server entity-framework temporal-database entity-framework-6

1
推荐指数
1
解决办法
1657
查看次数