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 7003925
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:07:56+00:00 2026-05-27T21:07:56+00:00

So, I have an Invoice object like so: public class Invoice { public virtual

  • 0

So, I have an Invoice object like so:

public class Invoice
{
    public virtual long InvoiceId { get; set; }

    public virtual string InvoiceNumber{ get; set; }
    public virtual Customer Customer { get; set; }
    public virtual Site Site { get; set; }

    public virtual IList<InvoiceLineItem> LineItems { get; set; }
    public virtual IList<InvoicePayment> Transactions { get; set; }
}

Then, I have an invoice line item like this

public class InvoiceLineItem
{
    public virtual long InvoiceLineItemId { get; set; }

    public virtual Invoice Invoice{ get; set; }
}

And finally, an invoice Payment

public class InvoicePayment
{
    public virtual long InvoicePaymentId { get; set; }

    public virtual Invoice Invoice{ get; set; }
}

The problem is this, in my underlying schema for InvoicePayment, I have InvoiceNumber, SiteId (to the Site object), and CustomerId (to the Customer object).

In InvoiceLineItem, I have InvoiceId linking back to Invoice.

So, my mapping for Invoice looks something like this:

public sealed class InvoiceMap : ClassMap<Invoice>
{
    public InvoiceMap()
    {
        Table("InvoiceView");

        Id(x => x.InvoiceId).GeneratedBy.Identity();


        Map(x => x.InvoiceNumber);

        References<Site>(x => x.Site, "SiteId");
        References<Customer>(x => x.Customer, "CustomerId");

        HasMany<InvoiceLineItem>(x => x.LineItems)
            .Inverse();

        HasMany<InvoicePayment>(x => x.Transactions)
            .KeyColumns.Add("SiteId")
            .KeyColumns.Add("EPayCustomerId")
            .KeyColumns.Add("InvoiceNumber")
            .Inverse();
    }
}

Line Items mapping

public class InvoiceLineItemMap : ClassMap<InvoiceLineItem>
{
    public InvoiceLineItemMap()
    {
        Table("InvoiceLineItems");

        Id(x => x.InvoiceLineItemId).GeneratedBy.Identity();

        References<FTNI.Core.Model.Invoice.Invoice>(x => x.Invoice, "InvoiceId");
    }
}

And finally my Invoice payments mapping

public class InvoicePaymentMap : ClassMap<InvoicePayment>
{
    public InvoicePaymentMap()
    {
        Table("InvoicePayments");

        Id(x => x.InvoicePaymentId).GeneratedBy.Identity();

        CompositeId()
            .KeyProperty(x => x.Site, "SiteId")
            .KeyProperty(x => x.Customer, "CustomerId")
            .KeyProperty(x => x.InvoiceNumber);

        References<Site>(x => x.Site, "SiteId");
        References<EPayCustomer>(x => x.Customer, "CustomerId");

        References<FTNI.Core.Model.Invoice.Invoice>(x => x.Invoice)
            .Columns("SiteId", "CustomerId", "InvoiceNumber")
            .Nullable();

    }
}

So, as it is, I am getting an error

Foreign key (FKE9F746C567E71B3F:InvoiceLineItems [InvoiceId])) must have same number of columns as the referenced primary key (InvoiceView [SiteId, CustomerId, InvoiceNumber])

How can I adjust my mappings so I join to the invoice payments on a composite id and the line items on the identity column?

  • 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-05-27T21:07:57+00:00Added an answer on May 27, 2026 at 9:07 pm

    the error message looks a bit weird. I would expect a CompositeId()... in InvoiceMap to produce this error.

    The error stems from the fact that each entity can only have 1 Id and the call to CompositeId overrides the previous call to Id, hence the Id of Invoice is the CompositeId and a single Column in InvoiceLineItem doesnt match.

    try the following:

    public class Invoice
    {
        public virtual long InvoiceId { get; set; }
    
        public virtual InvoiceIdentity Identity { get; set; }
    
        public virtual IList<InvoiceLineItem> LineItems { get; set; }
        public virtual IList<InvoicePayment> Transactions { get; set; }
    
    }
    
    public class InvoiceIdentity
    {
        public virtual string InvoiceNumber{ get; private set; }
        public virtual Customer Customer { get; private set; }
        public virtual Site Site { get; private set; }
        public Identity(string invoicenumber, Customer customer, Site site)
        {
            InvoiceNumber = invoicenumber;
            Customer = customer;
            Site = site;
        }
    }
    
    public sealed class InvoiceMap : ClassMap<Invoice>
    {
        public InvoiceMap()
        {
            Table("InvoiceView");
    
            Id(x => x.InvoiceId).GeneratedBy.Identity();
    
    
            Component(x => x.Identity, c =>
            {
                c.Map(x => x.InvoiceNumber);
    
                c.References(x => x.Site, "SiteId");
                c.References(x => x.Customer, "CustomerId");
            });
    
            HasMany(x => x.LineItems)
                .Inverse();
    
            HasMany(x => x.Transactions)
                .PropertyRef(i => i.Identity)
                .KeyColumns.Add("SiteId", "EPayCustomerId", "InvoiceNumber")
                .Inverse();
        }
    }
    
    public class InvoicePaymentMap : ClassMap<InvoicePayment>
    {
        public InvoicePaymentMap()
        {
            Table("InvoicePayments");
    
            Id(x => x.InvoicePaymentId).GeneratedBy.Identity();
    
            References(x => x.Invoice)
                .Columns("SiteId", "CustomerId", "InvoiceNumber")
                .PropertyRef(i => i.Identity)
                .Nullable();
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entity classes: public class Invoice { public int ID { get;
I have two classes Invoice and InvoiceItem. I would like Invoice to have a
I have a html file that has invoice details I would like to know
I have a query which produces a list of orders like this: Invoice Description
I have tree tables, Customer, Invoice and InvoiceRow with the standard relations. These I
Scenario: Say I am on an invoice details page. I have a customer name
I have two tables: Invoice (ID, InternalPrice, ExternalPrice) InvoiceSummary (InvoiceID, Variance ) In this
I have an object JobBreakdown that has_one :invoice . If a JobBreakdown has an
I have a model like this. #models.py class Payment(models.Model): unit_price = models.DecimalField(max_digits=12, decimal_places=2) discount
I have /invoices/ controller and @service object. When /services/1/invoices/new is called, a new @invoice

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.