如何从ms sql获取mvc中的模型的随机记录 [英] How get random record from ms sql for model in mvc
本文介绍了如何从ms sql获取mvc中的模型的随机记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
@foreach(MvcTest5.Models.Story s in Model)
{
<div class="modal-content">
<div class="modal-header">
<p>@s.Title</p>
</div>
<div class="panel-heading">
<p>Автор:@s.Author Добавлено:@s.Date.Date.ToString()</p>
</div>
<div class="modal-body">
<p>@s.Text</p>
<p><a href="#">Читать далее...</a></p>
</div>
<div class="modal-footer">
<p>Прочитано:@s.View Понравилось:@s.Like</p>
</div>
</div>
}
例如:
For example:
@foreach (MvcTest5.Models.Story s in Model.OrderByDescending(n=>n.Like).Take(2))
我从数据库中获得最后2条最佳记录。
但是如何在模型中使用lambda获取随机记录?或者是另一种方式?
我尝试过:
@ foreach(MvcTest5.Models.Story在Model.OrderByDescending(n => n.Like).Take(2))
and I get last 2 best record from database.
But how can I get random record using lambda in models? Or is another way?
What I have tried:
@foreach (MvcTest5.Models.Story s in Model.OrderByDescending(n=>n.Like).Take(2))
推荐答案
你可以通过多种方式做到。你也可以谷歌搜索一个合适的解决方案。
这里有一个给你
c# - 从Linq到Sql的随机行 - Stack Overflow [ ^ ]
You could do it many ways. Also you could google it for a suitable solution.
Here is one for you
c# - Random row from Linq to Sql - Stack Overflow[^]
这篇关于如何从ms sql获取mvc中的模型的随机记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文