RIA and DTO

RIA and DTO

At the moment (RC bits) WCF RIA doesn’t support custom DTO as parameters for domain service operations. If you define

Code Snippet
[ DataContract ]
public class MyCustomDTO
{
    [ DataMember ]
     public int MyPayload { get ; set ; }
    [ DataMember ]
     public string MyOtherPayload { get ; set ; }
}

You won't be able to do this

Code Snippet
[ Invoke ]
public void MyOperation( MyCustomDTO data)

Compiler will greet you with this encouraging message:

Operation named 'MyOperation' does not conform to the required signature. Parameter types must be an entity type or one of the predefined serializable types.

Well, don’t be scared, there is workaround (as usual) to make our custom DTO “RIA friendly” (or Entity type in RIA terms).

You need to do 2 simple but not obvious things

1. Make your class identifiable by providing RIA with identity property(ies)

 

Code Snippet
public class MyCustomDTO
{
    [ Key ]
     public int MyDummyKey { get ; set ; }

     public int MyPayload { get ; set ; }
     public string MyOtherPayload { get ; set ; }
}

Note that we don’t need WCF data contract attributes anymore – RIA code generator takes care of it

2. Expose our “entity” via domain service dummy Query

Code Snippet
[ Query ]
public IQueryable < MyCustomDTO > GetMyCustomDTODummy() { return null ; }

Now you can successfully compile your project and use your custom operation with custom DTO client side

Code Snippet
var ctx = ( OrderContext )orderDomainDataSource.DomainContext;
var data = new MyCustomDTO
{
    MyPayload = 13,
    MyOtherPayload = "Test"
};
ctx.MyOperation(data);

but what about more complex DTOs with sub lists (data graphs)? well, just wait for the next post ;)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值