Attribute Hell in OrmLite

As i documented in this post on StackOverflow.

We need to re-archaect part of the project considering the a multitude of attributes that are needed when objects get transported and saved to a database…

My question is: Is there anything stopping us from building a capability like whats found in EntityFramework.

So instead of doing

    [Index]
    public string UserAccountId { get; set; }

We could do this:

modelBuilder 
    .Entity<UserEntity>() 
    .Property(t => t.UserAccountId) 
    .AddColumnIndex(new IndexAnnotation(new IndexAttribute("IX_Name") {});

Its clear all of the cababilties exist to add and remove indexes.

All thats required is to take whats there and changed it into a fluent version… Right?

Why are you using #define’s to exclude attributes, why don’t you just leave them always defined?

ServiceStack Attributes relies on the implementation and dependency-free ServiceStack.Interfaces project which should the the only project your models and DTOs need to reference.

Attributes are typically a compile-time metadata construct so you’re normally not going to be able to add the fluently like this, but ServiceStack does provide an API to add them dynamically, so you should be able to do something like:

typeof(Model)
    .AddAttributes(new IndexAttribute());

This is unique to ServiceStack, other libraries may not offer a way to add attributes dynamically. Is there a reason why you can’t just include both, e.g:

[Index, Indexed]
public string UserAccountId { get; set; }

Assuming this class:

public class UserEntity : IUserEntity
{
    public string UserAccountId { get; set; }

    public UserEntity()
    {

    }
}

Would this set it at runtime?

   typeof(UserEntity).GetProperty("UserAccountId").AddAttributes(new IndexAttribute());

Yeah, also note they should be configured once on Startup before using those tables in OrmLite.