entitytypebuilder<> does not contain a definition for hasrequired

asp.net-core asp.net-core-2.1 ef-code-first ef-fluent-api entity-framework-core

Question

I have below code

using System;
using IranKala.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace IranKala.Persistence.Configurations
{
    public class PriceConfiguration : IEntityTypeConfiguration<Price>
    {
        public void Configure(EntityTypeBuilder<Price> builder)
        {
            builder.HasKey(e => e.PriceId);
            builder.Property(e => e.PriceId).ValueGeneratedOnAdd();
            builder.HasRequired
        }
    }
}

and I receive below error when try to use this enter link description here

entitytypebuilder<> does not contain a definition for hasrequired

1
0
4/21/2019 4:53:00 PM

Accepted Answer

Check out the Required and Optional Relationships in the EF Core Documentation.

Specifically I think you'll want something like:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<MyEntity>()
        .HasOne(p => p.Relationship)
        .IsRequired();
}

Or something like that - you haven't given much information to go on

9
5/29/2018 6:13:15 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow