具有不同 ID 类型的任何类型映射
我正在为电话簿中的联系人开发一个活动规划应用程序。避免所有 public virtual
和 protected
内容,我的 Contact
类如下所示:
class Contact {
//...
Int32 Id { get; private set; } //primary key;
String Name { get; private set; }
//...
}
一位客户要求我处理他自己的电话簿和我的应用程序的电话簿一。所以我想从 Contact
中提取一个 IContact
接口,并添加另一个类 InternalContact
(这个名字很糟糕,我知道),实现相同的界面。问题是客户的数据库使用分配的字符串作为主键,因此 Contact
的 Id 类型和 InternalContact
的 Id 类型将不同。即使 Id 类型不同,是否可以使用
类型映射来映射 Invitation.Contact
属性?
提前致谢, 朱利奥
I'm working on an event-planning application for the contacts in a phone book. Avoiding all the public virtual
and protected
stuff, my Contact
class looks like:
class Contact {
//...
Int32 Id { get; private set; } //primary key;
String Name { get; private set; }
//...
}
A customer asked me to handle both his own phone book and my application's one. So I thought to extract an IContact
interface from Contact
, and to add another class InternalContact
(this name sucks, I know), implementing the same interface. The problem is that the customer's db uses an assigned string as a primary key, so Contact
''s Id type and InternalContact
's Id type will be different. Is it possible to map the Invitation.Contact
property using an <any>
type mapping, even is the Id types are different?
Thanks in advance,
Giulio
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定这是否是您所要求的,但您可以执行类似的操作来创建类:
Not sure if this is what you are asking but you could do something like this to create the classes: