1

I have the following ValueMember

public class ApplicationName : ValueObject
{
    public string FirstName { get; }
    public string LastName { get; }

    protected ApplicationName()
    {
    }

    private ApplicationName(string firstName, string lastName)
        : this()
    {
        FirstName = firstName;
        LastName = lastName;
    }
    
    etc...
}

in the following class (Asp.Net Core IdentityUser)

public class ApplicationUser : IdentityUser<long>
{
    public ApplicationUserName Name { get; set; }
}

Those columns (FirstName, LastName) along with the Email column are part of a db index. I have the following in my dbcontext:

modelBuilder.Entity<ApplicationUser>(x =>
{
    x.OwnsOne(p => p.Name, p =>
    {
        p.Property(pp => pp.FirstName).HasColumnName("FirstName");
        p.Property(pp => pp.LastName).HasColumnName("LastName");
    });
    x.HasIndex(p => new { p.Name, p.Email });
});

When I run my app I get the following error System.InvalidOperationException: ''Name' cannot be used as a property on entity type 'ApplicationUser' because it is configured as a navigation.'

How can I set the index without receiving the above error?

pantonis
  • 5,601
  • 12
  • 58
  • 115
  • 1
    It seems that current version of EF Core (EF Core 5) does not support this via fluent API. For anyone out there having the same issue here is a link to a workaround by Microsoft guys ```https://github.com/dotnet/efcore/issues/11336``` – pantonis Jan 23 '21 at 14:52

0 Answers0