开发者

Fluent NHibernate - Mapping results from stored procedure into multiple models

I'm trying to map the results of a stored procedure into a model that contains another model several times. I'm not sure if this is possible, but wanted to ask and see if this is a valid approach, or if it would 开发者_StackOverflowbe better to define everything out individually.

My model classes look like this:

public class ClientSummary {
    public virtual int Id { get; set; }
    public virtual int Client_ID { get; set; }
    public virtual string Client_Name { get; set; }
    public virtual string State { get; set; }
    public virtual EDITotal Totals { get; set; }
    public virtual EDITotal In_Totals { get; set; }
    public virtual EDITotal Out_Totals { get; set; }
    public virtual EDITotal Direct_Totals { get; set; }
    public virtual EDITotal CPN_Totals { get; set; }
}
public class EDITotal {
    public virtual int Count { get; set; }
    public virtual double Charges { get; set; }
    public virtual double StateSavings { get; set; }
    public virtual double PPOSavings { get; set; }
    public virtual float PPO_Pct_Bill { get; set; }
    public virtual float PPO_Pct_State { get; set; }
    public virtual int Unique_TaxIds { get; set; }
}

What I'm not sure of is what my class map would look like in Fluent NHibernate, or if something like this is possible. I'm mainly trying to keep things tidy, and reusable. I'm sure I'll have other reports that will use similar metrics. Am I going about this the right way, or do I really need to define a full model for each report I build? This is all taking place inside a MVC Web application.

Thanks in advance!


Yes this is indeed possible and right or wrong you can get it working with the way you have your classes setup. To do this, you can use a mapper like this:

public class ClientSummaryMappingOverride : IAutoMappingOverride<ClientSummary>
{
    public void Override(AutoMapping<ClientSummary> mapping)
    {
        mapping.References(x => x.Totals, "Totals_id");
        mapping.References(x => x.In_Totals, "In_Totals_id");
        mapping.References(x => x.Out_Totals, "Out_Totals_id");
        mapping.References(x => x.Direct_Totals, "Direct_Totals_id");
        mapping.References(x => x.CPN_Totals, "CPN_Totals_id");
    }
}

Once you have your map configured, you just need to make sure your Stored Procedure or SQL Query returns the ClientSummary records with the appropriate "Totals_id" type fields. NHibernate will pick up those ids and map them to the correct data (Lazy Load I believe, depending on your conventions or other mappings).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜