将泛型与父/子实体一起使用
我有一个实体 A 和一个实体 B。B 继承自 A,并且是 A 的超集。我在 .ascx 上有一个方法,当前加载控件属性并绑定来自 A 实体的数据。我想扩展该方法以包含 B。我想我需要创建一个包含两者的所有字段的实体,然后将 A 或 B 转换为组合实体类型。有人还有其他建议吗?
I have a entity A and a entity B. B Inherits from A and is a superset of A. I have a method on the .ascx that currently loads control properties and binds the data from the A entity. I would like to expand the method to include B. I think I would need to create an entity that contains all of the fields from both and then cast the A or B to the Combined entity type. Anyone have any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解你的问题,我会避免强制转换,而是创建一个
BindB(B b)
方法,将对象传递给现有的Bind(A a)
方法(不由于态射而需要强制转换),然后执行 B 属性的附加绑定。您建议的方法需要在调用之前强制转换为“超级对象”,仅对您刚刚隐藏的数据(对象的实际类型)进行有条件的操作。没有多大意义。If I understand your question, I would avoid the casting and instead create a
BindB(B b)
method that passes the object to the existingBind(A a)
method (no cast required thanks to morphism), then performs the additional binding for the B properties. The method you are suggesting will require a cast to the "super-object" before calling, only to operate conditionally on data you just hid (the actual type of the object). Doesn't make much sense.