1、只要是安装有framework4.0以后版本均可以这样随机取数据 var iquer= ( from a in new BackendDBContext().Categories orderby Guid.NewGuid() select a).Take(3);
2、linq to sql中还可以在dbcontext下定义
[Function(Name = "NEWID", IsComposable = true)]
public Guid NEWID() { return ((Guid)(this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod()))).ReturnValue)); }
然后你就可以直接调用了
var iquer= ( from a in new BackendDBContext().Categories orderby new dbcontext().NEWID() select a).Take(3);