如何以随机顺序返回匹配的实体?
要明确这是Entity Framework的东西和LINQ to Entities.
(航空代码)
IEnumerable<MyEntity> results = from en in context.MyEntity
where en.type == myTypeVar
orderby ?????
select en;
Run Code Online (Sandbox Code Playgroud)
谢谢
编辑:
我尝试将其添加到上下文中:
public Guid Random()
{
return new Guid();
}
Run Code Online (Sandbox Code Playgroud)
并使用此查询:
IEnumerable<MyEntity> results = from en in context.MyEntity
where en.type == myTypeVar
orderby context.Random()
select en;
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误:
System.NotSupportedException: LINQ to Entities does not recognize the method 'System.Guid Random()' method, and this method cannot be translated into a store expression..
Run Code Online (Sandbox Code Playgroud)
编辑(当前代码):
IEnumerable<MyEntity> results = (from en in context.MyEntity
where …
Run Code Online (Sandbox Code Playgroud)