使用 EF 检索大数据
Retrieve Big data using EF
我有两个table"Kelime"
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; }
}
两个table都包含超过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 _kelimecim = _rk.All().Where(w => !kelimeIdler.Contains(w.ID)).FirstOrDefault();
我正在尝试使用 "Kelime"、"Kelime List" 或其 "id",无论哪个不在我的 "Anlam" table 中都没有关系。 "contains" 部分超时。我尝试编写非聚集索引,但它不接受子查询。我应该怎么做才能达到我想要的?非常感谢。
private static DataContext _context;
public static DataContext ContextOlustur()
{
if (_context == null)
{
_context = new DataContext();
}
return _context;
}
将此模式添加到我的数据上下文 class 解决了我的问题。因为我的查询使用了两个不同的上下文,所以连接数据库时出现问题并超时。此模式可防止创建另一个上下文。
我有两个table"Kelime"
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; }
}
两个table都包含超过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 _kelimecim = _rk.All().Where(w => !kelimeIdler.Contains(w.ID)).FirstOrDefault();
我正在尝试使用 "Kelime"、"Kelime List" 或其 "id",无论哪个不在我的 "Anlam" table 中都没有关系。 "contains" 部分超时。我尝试编写非聚集索引,但它不接受子查询。我应该怎么做才能达到我想要的?非常感谢。
private static DataContext _context;
public static DataContext ContextOlustur()
{
if (_context == null)
{
_context = new DataContext();
}
return _context;
}
将此模式添加到我的数据上下文 class 解决了我的问题。因为我的查询使用了两个不同的上下文,所以连接数据库时出现问题并超时。此模式可防止创建另一个上下文。