-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow database default values for FK properties that are part of a composite key #29047
Conversation
@@ -708,7 +708,7 @@ static bool IsNotNullAndFalse(object? value) | |||
{ | |||
foreach (var key in entityType.GetDeclaredKeys()) | |||
{ | |||
foreach (var property in key.Properties) | |||
foreach (var property in key.Properties.Where(p => !p.IsForeignKey())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make sense to also stop warning on composite PKs that don't contain an FK?
cdfa03c
to
6937078
Compare
Coming back to this issue #27299 which was fixed with this merge. Setup:
BaseModel: public abstract class BaseModel
{
public virtual Tenant Tenant { get; set; }
public virtual string TenantId { get; set; }
}
//Inherited Entity A
public class A : BaseModel
{
[Key]
[MaxLength(36)]
public string SomeKeyField {get; set; }
public string Name { get; set; }
public virtual ICollection<B> ChildListOfB { get; set; }
}
//Child Entity B
public class B : BaseModel
{
public string SomeExtId { get; set; }
public string SomeOtherValue { get; set; }
}
//Tenant Entity
public class Tenant
{
[Key]
[MaxLength(36)]
public string TenantId {get; set; }
}
// OnModelCreating showing for B for now - same for all entities
modelBuilder.Entity<B>().HasKey(pi => new { pi.TenantId, pi.SomeExtId, pi.SomeOtherValue });
modelBuilder.Entity<B>().Property(e => e.TenantId).HasValueGenerator<VG>();
//Value Generator (VG)
public class VG: ValueGenerator<string>
{
public override bool GeneratesTemporaryValues => false;
public override string? Next(EntityEntry entry)
{
var s = (entry.Context as OwnDbContext);
if (s != null)
return s.SomeProp.GetTenantId();
return null;
}
} Exception:
Current workaround: entityEntry.CurrentValues["TenantId"] = _internalField.GetTenantId(); Versions |
@localhost09 Please open a new issue and attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing so that we can investigate. |
Fixes #27299