Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle default data in an application using NHibernate
    primarykey
    data
    text
    <p>I'm working on an application that uses SQL Server and NHibernate. We have the concept of default data (complex entities) that needs to be created for each new entity. This data can be changed on a per-user basis. However, we're struggling with the best way to create this data.</p> <p>For example, lets say my application has a <code>Store</code> entity which has several default <code>Product</code>s that I want to create when a new <code>Store</code> gets created. Anything about a<code>Product</code> can be modified by managers of each <code>Store</code>.</p> <p>As I see it, there are two main options:</p> <ol> <li>Keep the default data in code and write it to the database once the new entity is created.</li> <li>Keep the default data in the database and move it over with a stored procedure/raw SQL when the entity is created.</li> </ol> <p>Instinctively, I lean toward option two, since databases are great at moving and manipulating sets of data, and option one would require a ton of messy code that could get out of hand.</p> <p>However, writing a stored procedure or raw SQL presents its own issues: </p> <ul> <li>We would have to re-write the stored procedure or SQL depending on the database we're using</li> <li>We would be subverting the ORM in a way (not sure if this is actually wrong). That is, we'd be moving data around without using NHibernate</li> </ul> <p>I found <a href="http://ayende.com/Blog/2006/04/18/BulkDataOperationsUsingNHibernate.aspx" rel="nofollow">this</a> article by Ayende Rahien which outlines how to perform a bulk delete. I am thinking that doing something similar for inserting default data would be fine. I also found an nhibernate users groups post (called "Schema export and default data"--SO won't let me post two links) that describes a similar situation, but it doesn't seem like there's a consensus on what the right solution is (although Ayende does offer some feedback and suggests that the data live in the database).</p> <p>After writing this, I'm leaning even more toward using a stored procedure, I'm just worried about possible pitfalls of mixing two database access strategies (directly calling SProcs and using an ORM).</p> <p>Any feedback is appreciated!</p> <p><strong>Edit:</strong> Removed "immutable" language. I'm specifically talking about default data that can change so I think this term was incorrect/confusing here.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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