You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I already have a table in database for the the following entity:
public class EmployeeAddress
{
public long EmployeeId { get; set; }
public string AddressType { get; set; }
public string AddressText { get; set; }
public string Country { get; set; }
public string City { get; set; }
public string PostCode { get; set; }
public string AdditionalInfo { get; set; }
}
Where EmployeeId and AddressType are the composite primary key.
Now I have added MaxLength attribute on AddressType as follows:'
public class EmployeeAddressConfiguration : IEntityTypeConfiguration<EmployeeAddress>
{
public void Configure(EntityTypeBuilder<EmployeeAddress> builder)
{
builder.ToTable("EmployeeAddresses");
builder.HasKey(ea => new { ea.EmployeeId, ea.AddressType });
builder.Property(ea => ea.AddressType).HasMaxLength(10).IsRequired();
......
}
}
Now after applying update-database command, getting the following error:
The object 'PK_EmployeeAddresses' is dependent on column 'AddressType'.
ALTER TABLE ALTER COLUMN AddressType failed because one or more objects access this column.
It seems that I cannot alter AddressType column without removing this from the composite primary key. Actually EF Core should have dropped the composite primary and recreated if any of the columns of the composite primary is altered.
I already have a table in database for the the following entity:
Where
EmployeeId
andAddressType
are the composite primary key.Now I have added
MaxLength
attribute onAddressType
as follows:'And Generated migration as follows:
Now after applying
update-database
command, getting the following error:It seems that I cannot alter
AddressType
column without removing this from the composite primary key. Actually EF Core should have dropped the composite primary and recreated if any of the columns of the composite primary is altered.Further technical details
EF Core version: 3.0
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET Core 3.0)
Operating system:
IDE: (e.g. Visual Studio 2019 16.3.10)
The text was updated successfully, but these errors were encountered: