我有一张这样的桌子:
idinterpretation | iddictionary | idword | meaning
1 1 1115 hello
2 1 1115 hi
3 1 1115 hi, bro
5 1 1118 good bye
6 1 1118 bye-bye
7 2 1119 yes
8 2 1119 yeah
9 2 1119 all rigth我试着得到不同的行(不同的虚词)。所以,一开始我试着:
return dc.interpretations.Where(i => i.iddictionary == iddict).
ToList<interpretation>().Distinct(new WordsInDictionaryDistinct()).
OrderBy(w => w.word.word1).Skip(iSkip).Take(iTake);但是我的表中有大约300.000行,这是错误的解决方案。
然后,我试着:
IEnumerable<interpretation> res = (from interp in dc.interpretations
group interp by interp.idword into groupedres
select new interpretation
{
idword = groupedres.Key,
idinterpretation = groupedres.SingleOrDefault(i => i.idword == groupedres.Key).idinterpretation,
interpretation1 = groupedres.SingleOrDefault(i => i.idword == groupedres.Key).interpretation1,
iddictionary = groupedres.SingleOrDefault(i => i.idword == groupedres.Key).iddictionary
}).Skip(iSkip).Take(iTake);我犯了错误:@foreach (interpretation interp in ViewBag.Interps) System.NotSupportedException: Explicit construction of entity type 'vslovare.Models.interpretation' in query is not allowed.
这真的是一种获取不同行并在最后一行中使用的方法吗?
idinterpretation | iddictionary | idword | meaning
1 1 1115 hello
5 1 1118 good bye
7 2 1119 yes 字典:
dictionary table
iddictionary | dictionary_name文字:
word table
idword | word_name解释:
interpretation table
idinterpretation | iddictionary | idword | meaning发布于 2011-03-20 16:31:36
我认为您的第二次尝试即将完成--您可能需要使用GroupBy子句才能在SQL中工作。
类似于:
var query = from row in dc.interpretations
where row.iddictionary == iddict
group row by idword into grouped
select grouped.FirstOrDefault();
return query.OrderBy(w => w.word.word1).Skip(iSkip).Take(iTake);关于查询时间太长的原因--通常情况下,如果查询速度慢,这将是因为您正在搜索和返回的数据非常大--或者因为它在数据库级别的索引很差。为了帮助查找,它正在分析或分析您的查询--请参阅本文在MSDN http://msdn.microsoft.com/en-us/magazine/cc163749.aspx上的内容。
https://stackoverflow.com/questions/5369406
复制相似问题