views:

19

answers:

1

hi all I've seen similar questions asked, but the answers haven't helped me yet. I am modelling TPH in my system (going POCO by the way), for data that is displayed in a Treeview (some sort of collection of the superclass is loaded and displayed). Now I need to do various things (such as UI styling, bizrules etc) based on the type of each object. Comparisons on the Type of the object is inadequate for several reasons (which I won't go into now). What I really need is just a simple representation of that discriminator as a property. It can be read-only (in fact, it should be, for obvious reasons). I get that EF doesn't want to allow you to (effectively) mess with the type of the object, but really? Any thoughts?

A: 

You can't do it. But since the discriminator value and the type are one and the same thing, it's less than clear why you say "Comparisons on the Type of the object is inadequate for several reasons (which I won't go into now)."

Craig Stuntz
hi Craig. The discriminator value in the db could be "ORG" but the type could be Organisation. Then of course there are the proxies, so there's an extra type. Its possible, yes, but doesn't seem to fit in the functional-programming paradigms (which I'm new to)I'll give an example. I have a treeview, where each node has an icon, according to its type. I need to set "Org" or "Emp" as my icon attribute. In my case, I'm projecting my IEnumerable<Node> to a JSON structure (for my tree). It would be great to set the icon attrib to the discriminator valu.
baldric
`var icon = node is Organization ? orgIcon : empIcon;` should do the trick.
Craig Stuntz