开发者

How to limit the fields returned from Silverlight 4 RIA services query

I'm using RIA services with Silverlight 4 and would like to limit the fields that are retur开发者_C百科ned from the service. For example:

TableA:
  ID
  Field1
  Field2
  Field3

TableB:
  ID
  TableAID (foreign key)
  Field1
  RestrictedField2

In my domain service class I have something like this that was generated when I created the service. I added the includes (which are working fine):

<RequiresAuthentication()>
Public Function GetTableA() As IQueryable(Of TableA)
    Return Me.ObjectContext.TableA.Include("TableB")
End Function

My question is, how do I get all of the columns from TableA and also get Field1 from TableB without returning the RestrictedField2? I'm pretty sure this is done through some Linq fanciness, but I'm not quite sure how.

Thanks! Matt

Update

One requirement that I didn't list above. The column must be removed on the server side as the data in RestrictedField1 cannot have any chance of being sent to the client. Also, I will need to use this field in a different domain service method (protected with RequiresRoleAttribute), so I can expose the information to an administrator. This requirement means that I don't want to create a different complex type and return that. I would prefer to continue working with the EF model type.


Check this link, I think it may solve your problem without the need of a view model

http://social.msdn.microsoft.com/Forums/en/adodotnetentityframework/thread/ab7b251a-ded0-487e-97a9-

I appears you can return an anonymous type then convert it to your needed type.


Based on some information that I found, the best way to accomplish what I need is to create a view in the database and expose the data I need via EF and RIA Services. This appears to be the best solution available.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜