12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Data.Entity.Core.Objects.DataClasses;
- namespace Bowin.Common.Linq.Entity
- {
- public static class SqlFunctionEx
- {
- /// <summary>
- /// 在linq to entity中使用SqlServer.NEWID函数
- /// </summary>
- [EdmFunction("SqlServer", "NEWID")]
- public static Guid NewId()
- {
- return Guid.NewGuid();
- }
- /// <summary>
- /// 随机排序扩展方法
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="source"></param>
- /// <returns></returns>
- public static IQueryable<T> OrderByNewId<T>(this IQueryable<T> source)
- {
- return source.OrderBy(d => NewId());
- }
- }
- }
|