Код: Выделить всё
public static IndexBuilder HasIndexUnique
(
this EntityTypeBuilder builder,
string indexName,
IEnumerable includeExpressions
) where TEntityType : class
{
if ((includeExpressions is null) || (!includeExpressions.Any()))
{
var currentMethod = MethodBase.GetCurrentMethod();
throw (new Exception($@"The method [{currentMethod?.DeclaringType?.FullName}.{currentMethod?.Name}] was called without any [{nameof(includeExpressions)}]."));
}
var propertyNames = includeExpressions
.Select
(
e =>
// Casting issue depending on what was sent in.
((MemberExpression) ((UnaryExpression) e.Body).Operand).Member.Name
)
.ToArray();
var indexBuilder = builder
.HasIndex
(
propertyNames,
$@"{indexName}"
)
.IsUnique(unique: true);
return (indexBuilder);
}
Код: Выделить всё
builder
.HasIndexUnique
(
"Index_IndexName_Unique",
e => e.ModelId,
e => e.ModelEntityPrincipleId,
e => e.ModelEntityDependentId,
e => e.ModelEntityBridgeId
);
Код: Выделить всё
builder.HasIndexUnique("Index_IndexName_Unique", e => e.Name);
// Exception at this line:
((MemberExpression) ((UnaryExpression) e.Body).Operand).Member.Name
System.InvalidCastException: 'Unable to cast object of type 'System.Linq.Expressions.PropertyExpression' to type 'System.Linq.Expressions.UnaryExpression'.'
Код: Выделить всё
Int64, String, DateTime, Object, Byte []
РЕДАКТИРОВАТЬ:
Код: Выделить всё
public partial class ModelEntityRelationship:
IEntity
{
public virtual long Id { get; set; }
public virtual string Name { get; set; }
public virtual long ModelId { get; set; }
public virtual Model Model { get; set; }
public virtual long ModelEntityPrincipleId { get; set; }
public virtual ModelEntity ModelEntityPrinciple { get; set; } = new();
public virtual long ModelEntityDependentId { get; set; }
public virtual ModelEntity ModelEntityDependent { get; set; } = new();
public virtual long? ModelEntityBridgeId { get; set; }
public virtual ModelEntity? ModelEntityBridge { get; set; }
}
Подробнее здесь: https://stackoverflow.com/questions/791 ... ccordingly
Мобильная версия