开发者

Different types of Id when exposing DTO over WCF

Lets say we have a simple DTO with properties Id, Name. If this DTO comes from database through some data layer, Id should be of type int. If this DTO comes from Activ开发者_如何学Pythone Directory, through some data layer, Id should be of type Guid.

What would be the best way to implement this?


The easiest way is to simply have two properties each of their appropriate type:

public Guid ActiveDirectoryID {get;set;};

public int DatabaseID {get;set;};

As an alternative you can define the ID property as an Object and implement it with an overloaded GetID() and SetID() for both types.

It's possible but not trivial to convert between a Guid and Int types.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜