Не удалось сопоставить свойство «Компания» «Demand.Company», поскольку поставщик базы данных не поддерживает этот тип. ⇐ C#
Не удалось сопоставить свойство «Компания» «Demand.Company», поскольку поставщик базы данных не поддерживает этот тип.
I'm creating class maps for my models but this type error keeps happening when the application tries to migrate the database. I initially thought that the problem was the absence of the shadow properties for the relationships between tables, but it persists even after they are created and configured.
Here are my models and the respective Mappings:
Company Model
namespace Api.Domain.Model { public class Company : BaseTable { public virtual int Id { get; protected set; } public virtual string Name { get; set; } public virtual string Cnpj { get; set; } public virtual string Email { get; set; } public virtual string Description { get; set; } public virtual IEnumerable Demands { get; set; } } } Demand Model
namespace Api.Domain.Model { public class Demand : BaseTable { public virtual int Id { get; protected set; } public virtual string Title { get; set; } public virtual string Description { get; set; } public virtual Company Company { get; set; } public virtual string Department { get; set; } public virtual string Benefits { get; set; } public virtual string Details { get; set; } public virtual string Restrictions { get; set; } public virtual string Keywords { get; set; } public virtual Person Responsible { get; set; } public virtual IEnumerable Matches { get; set; } // Shadow Properties public virtual int CompanyId { get; set; } public virtual int ResponsibleId { get; set; } } } Company Map
namespace Api.Domain.Map { public class CompanyMap : BaseMap { protected override void Configure(EntityTypeBuilder builder) { // Primary Key builder.HasKey(x => x.Id); // Properties builder.Property(x => x.Id).UseIdentityColumn(); builder.Property(x => x.Name).IsRequired().HasMaxLength(255); builder.Property(x => x.Cnpj).IsRequired().HasMaxLength(14); builder.Property(x => x.Email).IsRequired().HasMaxLength(255); builder.Property(x => x.Description).HasMaxLength(1000); // Relationships builder.Navigation(x => x.Demands); // Indexes builder.HasIndex(x => x.Cnpj).IsUnique(); builder.HasIndex(x => x.Email).IsUnique(); } } } Demand Map
namespace Api.Domain.Map { public class DemandMap : BaseMap { protected override void Configure(EntityTypeBuilder builder) { // Primary Key builder.HasKey(x => x.Id); // Properties builder.Property(x => x.Id).UseIdentityColumn(); builder.Property(x => x.Title).IsRequired().HasMaxLength(255); builder.Property(x => x.Description).IsRequired().HasMaxLength(1000); builder.Property(x => x.Department).HasMaxLength(255); builder.Property(x => x.Benefits).HasMaxLength(1000); builder.Property(x => x.Details).HasMaxLength(1000); builder.Property(x => x.Restrictions).HasMaxLength(1000); builder.Property(x => x.Keywords).HasMaxLength(255); // Relationships builder.Navigation(x => x.Matches); builder.HasOne() .WithMany(c => c.Demands) .HasForeignKey(x => x.CompanyId) .IsRequired(); builder.HasOne() .WithMany() .HasForeignKey(x => x.ResponsibleId) .IsRequired(); // Indexes builder.HasIndex(x => x.Company); builder.HasIndex(x => x.Responsible); } } } As the title says, the error is: The 'Company' property 'Demand.Company' could not be mapped because the database provider does not support this type. Consider converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.. Any idea What i am doing wrong?
Источник: https://stackoverflow.com/questions/781 ... e-database
I'm creating class maps for my models but this type error keeps happening when the application tries to migrate the database. I initially thought that the problem was the absence of the shadow properties for the relationships between tables, but it persists even after they are created and configured.
Here are my models and the respective Mappings:
Company Model
namespace Api.Domain.Model { public class Company : BaseTable { public virtual int Id { get; protected set; } public virtual string Name { get; set; } public virtual string Cnpj { get; set; } public virtual string Email { get; set; } public virtual string Description { get; set; } public virtual IEnumerable Demands { get; set; } } } Demand Model
namespace Api.Domain.Model { public class Demand : BaseTable { public virtual int Id { get; protected set; } public virtual string Title { get; set; } public virtual string Description { get; set; } public virtual Company Company { get; set; } public virtual string Department { get; set; } public virtual string Benefits { get; set; } public virtual string Details { get; set; } public virtual string Restrictions { get; set; } public virtual string Keywords { get; set; } public virtual Person Responsible { get; set; } public virtual IEnumerable Matches { get; set; } // Shadow Properties public virtual int CompanyId { get; set; } public virtual int ResponsibleId { get; set; } } } Company Map
namespace Api.Domain.Map { public class CompanyMap : BaseMap { protected override void Configure(EntityTypeBuilder builder) { // Primary Key builder.HasKey(x => x.Id); // Properties builder.Property(x => x.Id).UseIdentityColumn(); builder.Property(x => x.Name).IsRequired().HasMaxLength(255); builder.Property(x => x.Cnpj).IsRequired().HasMaxLength(14); builder.Property(x => x.Email).IsRequired().HasMaxLength(255); builder.Property(x => x.Description).HasMaxLength(1000); // Relationships builder.Navigation(x => x.Demands); // Indexes builder.HasIndex(x => x.Cnpj).IsUnique(); builder.HasIndex(x => x.Email).IsUnique(); } } } Demand Map
namespace Api.Domain.Map { public class DemandMap : BaseMap { protected override void Configure(EntityTypeBuilder builder) { // Primary Key builder.HasKey(x => x.Id); // Properties builder.Property(x => x.Id).UseIdentityColumn(); builder.Property(x => x.Title).IsRequired().HasMaxLength(255); builder.Property(x => x.Description).IsRequired().HasMaxLength(1000); builder.Property(x => x.Department).HasMaxLength(255); builder.Property(x => x.Benefits).HasMaxLength(1000); builder.Property(x => x.Details).HasMaxLength(1000); builder.Property(x => x.Restrictions).HasMaxLength(1000); builder.Property(x => x.Keywords).HasMaxLength(255); // Relationships builder.Navigation(x => x.Matches); builder.HasOne() .WithMany(c => c.Demands) .HasForeignKey(x => x.CompanyId) .IsRequired(); builder.HasOne() .WithMany() .HasForeignKey(x => x.ResponsibleId) .IsRequired(); // Indexes builder.HasIndex(x => x.Company); builder.HasIndex(x => x.Responsible); } } } As the title says, the error is: The 'Company' property 'Demand.Company' could not be mapped because the database provider does not support this type. Consider converting the property value to a type supported by the database using a value converter. See https://aka.ms/efcore-docs-value-converters for more information. Alternately, exclude the property from the model using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.. Any idea What i am doing wrong?
Источник: https://stackoverflow.com/questions/781 ... e-database
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Невозможно сопоставить свойство PropertyName, поскольку оно имеет тип List
.
Anonymous » » в форуме C# - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-