简体   繁体   中英

Using Generics with a Parent/Child entities

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?

If I understand your question, I would avoid the casting and instead create a BindB(B b) method that passes the object to the existing Bind(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM