开发者

Can ObjectQuery.OrderBy() use NEWID()?

I found that Entity SQL support NEWID(), but does ObjectQuery support it as well? http://msdn.micros开发者_StackOverflow中文版oft.com/en-us/library/bb738616.aspx,

Can I write objectquery like:

context.member.orderby("NEWID()").select("it.UserID");

or something like this? or I should write in other way?

I thought if entity sql support NEWID() function, it should be accepted by ObjectQuery also. Like you can use distinct(it.UserID), or BitWiseAND(it.UserID, 1) in ObjectQuery.Where() or Select().

Many thanks.


This is a SQL Server-specific canonical function, so it should be prefixed with 'SqlServer':

context.member.orderby("SqlServer.NEWID()").select("it.UserID");

Unfortunately, this will not work either: the Where extension method needs at least one reference to the immediate input scope.


Thanks Devart for response.

Actually, I found that I can use like:

var query1 = context.member.select("it.userid, SqlServer.NEWID() as newid").orderby("it.newid");

this can make random order for result, you will find that NEWID() is in the translated sql query.

but if you want to select partially result from 'query1' result set, you cannot write:

var query2 = context.member.select("it.userid, SqlServer.NEWID() as newid").orderby("it.newid").select("it.userid");

because when you use sql profiler to watch the sql that translated pass into sql server, you will find that the 'NEWID()' disappear.

However, I think 'query2' should be make sense. But it doesn't work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜