救急 --------- linq随机查询
linq中 想随机查询N条信息怎么做呢查了下 网上说是这样的:
在Northwind.designer.cs文件中添加
[Function(Name = "NEWID", IsComposable = true)]
public Guid NEWID()
{
return ((Guid)(this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))).ReturnValue));
}
然后可以用var results=(from c in db.Customers orderby NEWID()
select c).Take(10);
不过我的MVC项目中根本没那个文件
或者有没有其他方法实现 LINQ 随机 --------------------编程问答-------------------- 要添加System.Data.Linq 这个dll 或命名空间
--------------------编程问答-------------------- from c in db.Customers.AsEnumerable() orderby Guid.NewGuid() --------------------编程问答-------------------- var query= (from c in db.Customers
orderby Guid.NewGuid()).Take(10); --------------------编程问答--------------------
var results=(from c in db.Customers orderby Guid.NewGuid()--------------------编程问答--------------------
select c).Take(10);
++ --------------------编程问答--------------------
少写了点
--------------------编程问答-------------------- public partial class DbDataContext : System.Data.Linq.DataContext
var query= (from c in db.Customers
orderby Guid.NewGuid()
select c ).Take(10);
{
[Function(Name = "NEWID", IsComposable = true)]
public Guid NEWID()
{
return ((Guid)(this.ExecuteMethodCall(this,
((MethodInfo)(MethodInfo.GetCurrentMethod()))).ReturnValue));
}
} --------------------编程问答-------------------- orderby Guid.NewGuid()
补充:.NET技术 , LINQ