0

I have implemented the project of EntityFramework 6 into EntityFramework Core 3.1. I am new to Roslyn API.

Sample.cs

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
        modelBuilder.Entity<Contact>()
                    .HasOptional(c => c.Spouse)
                    .WithMany()
                    .HasForeignKey(c => c.SpouseId);
 }

has to become

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
        modelBuilder.Entity<Contact>()
                    .HasOne(c => c.Spouse)
                    .WithMany()
                    .HasForeignKey(c => c.SpouseId);
 }

Kindly someone help me that how to do that in Roslyn

Karthic G
  • 1,162
  • 1
  • 14
  • 31
  • 1
    This seems like something that could be done with find-and-replace, or at least find-all; can you clarify why you are trying to use Roslyn here? There may well be a reason - but it isn't an obvious direction. – Marc Gravell Jan 05 '21 at 08:05
  • how to find and replace in C# and roslyn is the my requirement.thats why. One more thing do you know what is the equivalent part of HasOptional() in EFCore – Karthic G Jan 05 '21 at 08:16
  • 1
    That's like saying "putting screws in with a hammer is my requirement, that's why". – Marc Gravell Jan 05 '21 at 08:35
  • ha ha...thanks.what is the equivalent part of HasOptional()? – Karthic G Jan 05 '21 at 10:22
  • see: https://stackoverflow.com/questions/35562483/equivalent-for-hasoptional-in-entity-framework-core-1-ef7 – Marc Gravell Jan 05 '21 at 10:39
  • yes, i referred that link already, they suggested as HasIndex() replacement. is it right? – Karthic G Jan 05 '21 at 13:36
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226881/discussion-between-karthic-g-and-marc-gravell). – Karthic G Jan 05 '21 at 16:34

0 Answers0