Composite Primary key #555
Unanswered
DataTowerSystems
asked this question in
Q&A
Replies: 2 comments 4 replies
-
Hi! I'm glad you find Finbuckle helpful! I'm at a conference today so I can't give you a full answer until later today, but I will make sure to respond. |
Beta Was this translation helpful? Give feedback.
2 replies
-
Do you have a simple repo that shows this problem you can link me to? Is the error happening when |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First of all thank you very much for this greate library.
My case is as following:
I have 2 tables (Entities) Product and Category
The product in domain:
public class Product : AuditableEntity, IAggregateRoot
{
public string ProductCode { get; set; } = string.Empty;
public string ProductDescription { get; set; } = string.Empty;
public string ProductCategoryCode { get; set; } = string.Empty;
public Category Category { get; set; } = default!;
}
And the Category in Domain:
public class Category : AuditableEntity, IAggregateRoot
{
public string CategoryCode { get; set; } = string.Empty;
public string CategoryDescriptionArabic { get; set; } = string.Empty;
public string CategoryDescriptionEnglish { get; set; } = string.Empty;
[NotMapped]
public string? TenantId { get; set; }
public ICollection Products { get; set; } = default!;
}
And in Infrastructure/ Persistence/ Configuration
The fluent API
public class CategoryConfig : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.IsMultiTenant();
}
public class ProductConfig : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.IsMultiTenant();
}
And this is how it looks in the Database
relations
Until now everything is Ok, the problem is when I create new Category and try to save it I got the following error:
“Unable to track an entity of type 'Category' because alternate key property 'TenantId' is null. If the alternate key is not used in a relationship, then consider using a unique index instead. Unique indexes may contain nulls, while alternate keys may not.”
I hope this is clear now.
Can you please help to solve this issue.
Again Thank you very much for your cooperation.
Beta Was this translation helpful? Give feedback.
All reactions