Note that there are some explanatory texts on larger screens.

plurals
  1. PODiscriminated unions in NHibernate
    text
    copied!<p>I'm wondering if there's any relatively easy way to extend NHibernate to support F#'s discriminated union. Not just a single IUserType or ICompositeUserType, but something generic that I can re-use regardless of the actual contents of the DU.</p> <p>For example, suppose I have a property called RequestInfo, which is a union defined as:</p> <pre><code>type RequestInfo = | Id of int | Name of string </code></pre> <p>This compiles into an abstract RequestInfo class, with concrete subclasses Id and Name. I can get all this info out just fine with F# reflection. In this case, I could store it in the database with "RequestInfo_Tag", "RequestInfo_Id", "RequestInfo_Name". </p> <p>As I'm a NHibernate newbie, what kind of problems am I going to run into trying to follow this approach? Are more complex cases going to be impossible to deal with? For example, what about nested discriminated unions? Is there a way I can "hand off" the reading of the rest of the union to another ICompositeUserType?</p> <p>More importantly, will this mess up my querying capabilities? Meaning, will I have to know the actual column names in the DB; I won't be able to do Criteria.Eq(SomeDiscUnion) and have it all sorted out?</p> <p>I'm not looking for a complete "provide code" answer, just some general advice if this is even worth going after (and some pointers on how), or if I should just rethink my model.</p> <p>Thanks!</p> <p>P.S. Not to be rude, but if your answer consists of "use C#", it's not very helpful. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload