【发布时间】:2019-07-26 02:44:38
【问题描述】:
以下是我从数据库中获取信息的查询。从性能的角度来看,我想在我的实体上使用AsNoTracking 方法。
var teamrole = (from role in _context.USERROLEs.AsNoTracking()
from team in _context.TEAMROLEs.AsNoTracking().Where(x => x.ID == role.ROLEID).DefaultIfEmpty()
from queue in _context.WORKQUEUEs.AsNoTracking().Where(x => x.ID == team.QUEID).DefaultIfEmpty()
where team.ROLECD == roleCode
select new { team, queue }).ToList();
这是我的上下文:
public partial class MyContext : DbContext
{
public MyContext() : base("MyContext")
{
Configuration.ProxyCreationEnabled = false;
Database.SetInitializer<MyContext>(null);
}
public virtual DbSet<ZTEAMROLE> ZTEAMROLEs { get; set; }
//Some other entities here...
}
实体:
[Table("TEAMROLE")]
public partial class TEAMROLE
{
[StringLength(36)]
public string ID { get; set; }
[StringLength(36)]
public string QUEID { get; set; }
//More Properties...
}
执行查询时遇到的错误teamrole
方法
System.Data.Entity.Infrastructure.DbQuery'1[XXX.Entities.TEAMROLE] AsNoTracking()在类型上声明System.Data.Entity.Infrastructure.DbQuery'1[XXX.Entities.TEAMROLE]不能用类型的实例调用System.Data.Entity.Core.Objects.ObjectQuery'1[XXX.Entities.TEAMROLE]
【问题讨论】:
-
您只需拨打
AsNoTracking一次。根据异常消息、查询和 DbContext 类型,您可以转换为属性_context.TEAMROLEs中集合的内存表示形式。
标签: c# oracle entity-framework linq