Note that there are some explanatory texts on larger screens.

plurals
  1. POFluent NHibernate and Stored Procedures
    primarykey
    data
    text
    <p>I have a basic Customer/Order/OrderItem/Product object graph. Customer has Many Orders, Order has Many Order Items, Product has many Order Items. These are successfully mapped using FNH.</p> <p>I've hit a snag with configuring a stored procedure &amp; fluent-nhibernate. There is not a native way to map stored procedures in fluent-hibernate FNH (version 1.0 RTM). There was a solution <a href="http://maonet.wordpress.com/2009/05/06/create-your-own-parts-to-merge-stored-procedure-into-fluent-nhibernate-mappings/" rel="nofollow noreferrer">here</a> about adding parts to class mappings but the AddPart call has been taken out of the release of FNH.</p> <p>The stored procedure is simple: </p> <pre><code>CREATE PROCEDURE [dbo].[OrderCountByCustomer] AS BEGIN SET NOCOUNT ON; SELECT c.name as [Customer.Name], CAST(count(o.id) as NVARCHAR) as [Customer.OrderCount] FROM customer c LEFT OUTER JOIN [order] o ON o.customer_id = c.id GROUP BY c.name END </code></pre> <p>There's a CustomerOrderSummary.hbm.xml in </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt; &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="NVAble.Orders.Core" namespace="NVAble.Orders.Core"&gt; &lt;sql-query name="OrderSummary"&gt; &lt;return class="CustomerOrderSummary"&gt; &lt;return-property column="Customer.Name" name="CustomerName" /&gt; &lt;return-property column="Customer.OrderCount" name="OrderCount" /&gt; &lt;/return&gt; EXEC [OrderCountByCustomer] &lt;/sql-query&gt; &lt;/hibernate-mapping&gt; </code></pre> <p>Here is the CustomerOrderSummary class def:</p> <pre><code>namespace NVAble.Orders.Core { public class CustomerOrderSummary { virtual public string CustomerName { get; set; } virtual public string OrderCount { get; set; } public override string ToString() { return string.Format("{0} {1}", CustomerName, OrderCount); } } } </code></pre> <p>However, when try to start a NH session i get error in named query <code>OrderSummary</code> with no other details.</p> <p>I'm probably missing something really simple that maps the <code>CustomerOrderSummary</code> class to the procedure, I don't know. That domain object obviously doesn't map directly to a table in the data base so I'm unsure if having a normal <code>&lt;class /&gt;</code> HBM mapping would work?</p> <p>Thanks in advance!</p>
    singulars
    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.
 

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