C# EF Index based on entity field and owned value object field

369 Views Asked by At

Any body know if it is possible to create index based on entity field and owned value object field using code-first in entity framework - dotnet core 3.

I have entity with this 2 fields and several more:

public string SomethingId { get; private set; }
public EmailAddress Email { get; private set; }

I try to create index in this way:

builder.HasIndex(p => new {p.Email.Address, p.SomethingId}).IsUnique();

But it doesn't work.

I get an error

The properties expression 'p => new <>f__AnonymousType3`2(Address = p.Email.Address, SomethingId = p.SomethingId)' is not valid. The expression should represent a simple property access: 't => t.MyProperty'. When specifying multiple properties use an anonymous type: 't => new { t.MyProperty1, t.MyProperty2 }'.

Thanks for every suggestion if it is possible to deal with this problem ;)

0

There are 0 best solutions below