Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用EF检索大数据_Sql_Performance_Entity Framework_Indexing_Repository - Fatal编程技术网

Sql 使用EF检索大数据

Sql 使用EF检索大数据,sql,performance,entity-framework,indexing,repository,Sql,Performance,Entity Framework,Indexing,Repository,我有两张桌子 public class Kelime { public int ID { get; set; } public string Word { get; set; } public DateTime Date { get; set; } } 安兰呢 public class Anlam { public int ID { get; set; } public string Meaning { get; set; } pub

我有两张桌子

public class Kelime
{

    public int ID { get; set; }

    public string Word { get; set; }

    public DateTime Date { get; set; }
}
安兰呢

public class Anlam
{

    public int ID { get; set; }

    public string Meaning { get; set; }

    public DateTime Date { get; set; }

    public int Kelimesi_ID { get; set; }
    [ForeignKey("Kelimesi_ID")]
    public virtual Kelime kelime { get; set; }
}
两个表都包含超过80k的数据。我认为它们不是很大,但我对这个问题有疑问:

Repository<Kelime> _rk = new Repository<Kelime>();
Repository<Anlam> _ra = new Repository<Anlam>();

IEnumerable<int> kelimeIdler = _ra.All().Select(s => s.Kelimesi_ID).Distinct();
int _kelimecik= _rk.Find(w => !kelimeIdler.Contains(w.ID)).ID;
或Kelime\u kelimecim=\u rk.All.Wherew=>!kelimeIdler.Containsw.ID.FirstOrDefault

我正在尝试获取Kelime,Kelime列表或其id。不在我的Anlam表中的不重要。当涉及到包含部分时,会出现超时。我试图编写非聚集索引,但它不接受子查询。我应该做什么来实现我想要的?多谢各位

private static DataContext _context;

public static DataContext ContextOlustur()
{
    if (_context == null)
    {
        _context = new DataContext();
    }

    return _context;
}

将此模式添加到我的数据上下文类解决了我的问题。因为我的查询使用了两种不同的上下文,这就是为什么连接数据库会出现问题并超时的原因。此模式阻止创建另一个上下文。

80k不是大数据。超时是由SQL Server引发的,因此EF不是真正的问题。您可以在SQL server Profiler中看到运行的查询,然后对其进行优化添加正确的索引感谢您的响应SQL server Profiler没有帮助,但正如您所说,ef不是问题所在。这个问题是基于我的数据上下文,我使用单例模式,我的问题消失了。