For a multi-column index, one has to repeat the index name for each
IndexAttribute data annotation over and over again. This requirement is rather error prone (in regard to typos) and it's clumsy.
Moreover, for a multi-column index, the requirement of providing ordinal numbers renders editing an EDM class cumbersome and error prone, too. One always has to make sure the ordinals are continuous and strictly monotonically increasing.
.
Just like the T-SQL syntax suggests, I'd suggest to apply the
IndexAttribute on class level.
This way you omit the clumsy name and ordinal requirement. Programmers would just give a comma-separated list of property names by means of an array of lambda expressions - and that's it:
[AttributeUsageAttribute(AttributeTargets.Class, AllowMultiple = true)]
public class IndexAttribute : Attribute
{
public IndexAttribute(Expression<Func<TEntity, Object>>[] properties
,bool[] descending = null)
{...}
}
Which would result in using something similar to:
[Index(new [] {x => x.Name, x => x.Country}, new [] {false, true})]
public class MyEntity
{
public int Id;
public string Name;
public string Country;
}
.
The original IndexAttribute, which is applied to properties, should be eased to mainly support single column indices by requiring merely the IsUnique constructor parameter:
[AttributeUsageAttribute(AttributeTargets.Property, AllowMultiple = true)]
public class IndexAttribute : Attribute
{
public IndexAttribute (bool isUnique)
{...}
}
.
Both new index types should derive an appropriate index name automatically.
Your thoughts?