【发布时间】:2016-02-26 00:09:30
【问题描述】:
我正在尝试将我的 LinQ 语句变成预编译语句。
我正在使用本指南:LinQ opti
我这样构建数据库连接:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
public DbSet<UserType> UserType { get; set; }
}
这个静态类看起来像这样:
public static class clsCompiledQuery
{
//UserType
public static Func<ApplicationDbContext, string, IQueryable<UserType>>
getUserTypeByCode = CompiledQuery.Compile((ApplicationDbContext db, string UserTypeCode)
=> from tbUserType in db.GetTable<UserType>()
where tbUserType.UserTypeCode == "PAR"
select tbUserType);
}
db.GetTable() 在 ApplicationDbContext 中不可用
有没有办法从 ApplicationDbContext 创建 GetTable?
这对我来说是新的领域,我在这方面有点迷失了。 这个任务/主题的原因是 LinQ 很慢,我需要找到更好的性能。
【问题讨论】:
-
您使用的是哪个版本的 EF 和 .net 框架?
-
EF 6.1.3, ASP.NET Identity 2.2.1 Witch包你是指.net框架吗?
-
.net 框架是您运行代码的“引擎”。我猜您使用的是 4.5 或 4.6;反正没关系——看看我的回答
标签: c# entity-framework linq