0

I'm making a software for electronic invoices. So each invoice(and every entity as well) in the system will have an universal GUID Id as the primary key but I want another auto incremented Integer column that will increments it's value according to the provider(user) that is issuing the invoice. For example: I have a provider A that has 10 invoices and each invoice has a number that start at 1 in ascending mode but everyone has an unique GUID and a provider B that has the same invoices with the same ascending number starting at 1 but again with unique GUIDs. This numbers help for searching more easily in the system, instead of searching millions invoices in the database by the GUID, you just put the invoice number that is attached to the provider and it's much more clear than simply putting an extensive GUID in the case for printing it. I hope I was clear.

Here the code:

 public void Configure(EntityTypeBuilder<Invoice> builder)
    {
        builder.HasKey(x => x.Id); //GUID

        builder.Property(x => x.Title)
            .IsRequired()
            .HasMaxLength(100);
        
        builder.Property(x => x.Description)
            .IsRequired();
        
        builder.Property(x => x.Date)
            .IsRequired();
        
        builder.Property(x => x.TotalValue)
            .IsRequired();

        builder.Property(x => x.TaxValue)
            .IsRequired();
        
        builder.HasOne(x => x.Taker);
        builder.HasOne(x => x.Provider);
        builder.HasOne(x => x.ServiceType);
    }
Gabriel Francisco
  • 301
  • 1
  • 2
  • 9
  • Are you aware of the performance considerations that come with using a GUID as a primary key? https://stackoverflow.com/questions/11938044/what-are-the-best-practices-for-using-a-guid-as-a-primary-key-specifically-rega/11938495 – Daniel Mann Sep 19 '21 at 16:10
  • Yes, I know it can slow down the db performance, but in this scenario, GUID also can be used as "security verification". – Gabriel Francisco Sep 19 '21 at 17:16
  • "provider A that has 10 invoices (...) and a provider B that has the *same* invoices". What is "same" here? I think this question is a lot clearer if you show sample data. – Gert Arnold Sep 19 '21 at 18:05
  • Try to check [this answare](https://stackoverflow.com/questions/25094711/entity-framework-auto-generate-guid) – Den Sep 19 '21 at 18:16
  • Sorry for the not clear information: I was referring to the "same" quantity of invoices each provider have. – Gabriel Francisco Sep 19 '21 at 21:51

0 Answers0