2015-11-16 23 views
0

获取大数据我有两个表 “Kelime”使用EF

public class Kelime 
{ 

    public int ID { get; set; } 

    public string Word { get; set; } 

    public DateTime Date { get; set; } 
} 

和 “Anlam”

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 DATAS。我不认为他们是非常大的,但我对这个查询有问题:

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 _kelimecim = _rk.All().Where(w => !kelimeIdler.Contains(w.ID)).FirstOrDefault();

我试图采取“Kelime”,“Kelime列表”或者它的“身份证”哪些不在我的“Anlam”表中并不重要。 “包含”部分有一个超时。我试图编写非聚集索引,但它不接受子查询。我该怎么做才能达到我想要的?非常感谢你。

+0

80k不是大数据。 SQL Server引发超时,所以EF不是真正的问题。你可以在SQL服务器(Profiler)中看到运行的查询,然后优化它添加正确的索引 – bubi

+0

谢谢你的回应sql server profiler does not帮助,但正如你所说,ef不是问题。问题是基于我使用“单例模式”的“数据上下文”,我的问题已经消失。 – nalpara

回答

0
private static DataContext _context; 

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

    return _context; 
} 

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