开发者

Different types of Id when exposing DTO over WCF

开发者 https://www.devze.com 2023-01-01 19:13 出处:网络
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, t

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

精彩评论

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