Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:42:29+00:00 2026-06-15T01:42:29+00:00

OK, I’m scratching my head once again. I have a class like so: public

  • 0

OK, I’m scratching my head once again. I have a class like so:

public class ReconciliationReportLineItem
{
    public virtual int ID { get; set; }
    public virtual int Category { get; set; }
    public virtual string FileName { get; set; }
    public virtual decimal Amount { get; set; }
    public virtual string BatchType { get; set; }
    public virtual DateTime CreatedTimeStamp { get; set; }
    public virtual string Currency { get; set; }
    public virtual decimal LocalAmount { get; set; }
    public virtual int NumberOfInvoices { get; set; }

    public override bool Equals(object obj)
    {
        var t = obj as ReconciliationReportLineItem;
        if (t == null) return false;
        return
            t.ID == this.ID
            && t.Category == this.Category;
    }

    public override int GetHashCode()
    {
        return string.Format("{0}{1}{2:yyyyMMddHHmmss}{3}{4}{5}{6}",
            this.FileName, this.BatchType, this.CreatedTimeStamp,
            this.NumberOfInvoices, this.LocalAmount, this.Amount,
            this.Currency).GetHashCode();
    }
}

and my fluent mapping file as such:

public class ReconciliationReportLineItemMapping : ClassMap<ReconciliationReportLineItem>
{
    public ReconciliationReportLineItemMapping()
    {
        Table("ReconciliationReportLineItem");

        CompositeId()
            .KeyProperty(x => x.ID, "id")
            .KeyProperty(x => x.Category, "category");

        Map(x => x.FileName)
            .Length(500)
            .Nullable()
            .Index("ixDatroseReconciliationReportLineItemFileName");

        Map(x => x.Amount)
            .Not.Nullable();

        Map(x => x.BatchType)
            .Not.Nullable();

        Map(x => x.CreatedTimeStamp)
            .Index("ixDatroseReconciliationReportLineItemCreatedTimeStamp")
            .Not.Nullable();

        Map(x => x.Currency)
            .Not.Nullable();

        Map(x => x.LocalAmount)
            .Not.Nullable();

        Map(x => x.NumberOfInvoices)
            .Not.Nullable();
    }
}

I populate the object, try to commit it, and I get an error like so:

ERROR: 23505: duplicate key value violates unique constraint "reconciliationreportlineitem_pkey"

The error sql shows that the members of the composite key (which were preset) are set to zero:

INSERT INTO ReconciliationReportLineItem (FileName, Amount, BatchType, CreatedTimeStamp, Currency, LocalAmount, NumberOfInvoices, id, category) 
VALUES (((NULL)::text), ((E'1065.47')::numeric), ((E'X200 batch created 20121027')::text), ((E'2012-10-27 08:39:00.000000')::timestamp), ((E'USD')::text), ((E'1065.47')::numeric), ((7)::int4), ((0)::int4), ((0)::int4))

…but I had specified the values before I tried to merge the records into the table. With a breakpoint, I was able to verify the objects did in fact have values before committing the session transaction.

What am I doing wrong? I need to specify the values of the keys.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:42:31+00:00Added an answer on June 15, 2026 at 1:42 am

    I don’t remember what the NHibernate default key generator is but try adding this to tell NH you’re going to assign the keys using a component as an identifier. There aren’t many examples for this approach but this forum post is partial one. Here is the updated code:

    // snipped >%
    
    CompositeId()
        .ComponentCompositeIdentifier<ReconciliationReportLineItemKey>
           (rrli => rrli.Key)
        .KeyProperty(k => k.Key.Id)
        .KeyProperty(k => k.Key.Category);
    
    // snipped >%
    

    You’ll need to add a new class for the key to make assignments for:

    public class ReconciliationReportLineItemKey
    {
        public virtual int Id { get; set; }
        public virtual int Category { get; set; }
    }
    

    and also add a property the component to your entity class:

    public class ReconciliationReportLineItem
    {
        // snipped >%
    
        public virtual ReconciliationReportLineItemKey Key { get; set; }
    
        // snipped >%
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.