|
★☆☆☆☆☆☆☆☆☆ |
积分:285 |
发帖:317 |
登录:2024/3/26 |
注册:2006/6/28 |
|
(1楼)Linq to SQL中实现orderby NewId
用于实现随机取数据。在DataClasses.designer.cs内加入如下代码: [System.Data.Linq.Mapping.DatabaseAttribute(Name="XJW")]
public partial class GaDB : System.Data.Linq.DataContext
{
[Function(Name = "NewId", IsComposable = true)]
public Guid NewId()
{
return (Guid)ExecuteMethodCall(this, MethodInfo.GetCurrentMethod() as MethodInfo).ReturnValue;
}
} 调用: var query = XJW.DB.TableName.OrderBy(t=>XJW.DB.NewId());
|