WithOptional with Entity Framework Core Base

I am trying to port my old application to the new EF Core, but I cannot find relationships such as:

HasRequired(o => o.Document).WithOptional(o => o.CancelNote); 

Are there any extension methods? I can not find in the docs.

HasRequired I think you can replace it with the HasOne() method, but what about WithOptional() ?

Another thing, according to docs, an entity does not use the virtual to create navigation properties, how will lazy loading work?

+5
source share
1 answer

You will not find the HasOptional equivalent method in EF7. By convention, if your FK property is nullable , your navigation property will be considered optional

  modelBuilder.Entity<Blog>() .HasOne(p => p.Document) .WithOne(i => i.CancelNote) .HasForeignKey<Document>(b => b.CancelNoteForeignKey); 

About your second question, EF Core (EF7) does not support Lazy Loading. In this link

+9
source

All Articles