菜鸟求助linq

来源:互联网  时间:2016/6/28 19:04:23

关于网友提出的“ 菜鸟求助linq”问题疑问,本网通过在网上对“ 菜鸟求助linq”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: 菜鸟求助linq
描述:

根据A表的bid分类,从A表中随机读取10条信息,方法怎么写


BSDataContext Context = new BSDataContext();
//随机读取10条主题
public IQueryable FindTopicRandom(int bid)
{
    return this.Context.Topic.Where???????
}

解决方案1:

引用 1 楼 jayrao5566 的回复:
C# code

(from n in A orderby NEWID() select n).take(10)

NENID() 是什么 解决方案2:

int[] model= new int[] { 4, 5, 6, 7, 8 }; var q = (from m in model orderby Guid.NewGuid() select m).Take(3); // 利用newGuid随机输出 条件就跟普通条件的一样了加到order by  之前就可以了 foreach (int item in model)
{
Console.WriteLine(item.ToString()); } //照葫芦慢慢画

上一篇sqlite数据库时不进的出现Unable to open the database file错误
下一篇使用正则表达式获取html指定标签下的内容。
明星图片
相关文章
《 菜鸟求助linq》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)