raresm
raresm

Reputation: 423

Adding ServiceStack OrmLite attributes in code instead of a property

Does ServiceStack.OrmLite support attributes using Linq like in EntityFramework?

Instead of decorating every property with [PrimaryKey] or [CustomField], have a initializer class that uses LinQ to set-up attributes for every property.

Something like

Entity<User>().SetCustomField(p => p.Id, Entity.PrimaryKey);

Possible?

Upvotes: 0

Views: 338

Answers (1)

mythz
mythz

Reputation: 143339

In OrmLite Id is automatically the Primary Key, otherwise the first property is assumed to be the primary key. But you can also use ServiceStack's dynamic attribute API to add attributes dynamically on StartUp, e.g:

typeof(User)
    .GetProperty("Id")
    .AddAttributes(new PrimaryKeyAttribute());

Upvotes: 2

Related Questions