Также предлагается обходной путь, который я сам не проверял.
я есть субъект, которому принадлежит другой объект
public class Entity1
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public virtual int ID { get; set; }
public string Property { get; set; }
public Entity2 Description { get; set; }
}
public class Entity2
{
public string Test { get; set; }
}
и мне нужно создать индекс по Entity1.Property и Entity2.Test. Конфигурация такая
builder.OwnsOne(pt => pt.Description);
builder.HasIndex(p => new { p.Property, p.Description.Test }).IsUnique();
//builder.HasIndex("Property", "Description_Test").IsUnique();
Я пробовал оба приведенных выше кода, но они не работают. Первое говорит
The properties expression 'p => new <>f__AnonymousType3`7(Property = p.DeviceClassId,
Test = p.Description.Test)' is not valid. The expression should represent a property
access: 't => t.MyProperty'. When specifying multiple properties use an anonymous type:
't => new { t.MyProperty1, t.MyProperty2 }'.
Parameter name: propertyAccessExpression
а второй говорит:
The property 'Description_test' cannot be added to the type 'Entity1' because there was no
property type specified and there is no corresponding CLR property or field. To add a
shadow state property the property type must be specified.
Можно ли этого достичь без изменения миграции вручную?