This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Is there a good way to get the TableName using only the Type of an entity? For instance, I have a public class monkeys<T> where T: Entity<Guid> Is there some way to do, for example, something like this: string tn = Entity.GetTableName<T>(); Maybe a way to expand via template modification? Any ideas would be appreciated. |
|
|
There's no direct way to query for the table name, but in most cases you can work it out reasonably easily: 1. If the entity class is a STI derived class (has the DiscriminatorAttribute), it has the same table name as its base class (note this may recurse if there is more than one level of hierarchy). 2. If the TableAttribute is present on the entity type, the table name is TableAttribute.Name. 3. If the TableAttribute is not present, and LightSpeedContext.PluralizeTableNames is false, the table name is the name of the entity class. 4. If the TableAttribute is not present, and LightSpeedContext.PluralizeTableNames is true, the table name is the name of the entity class, pluralised using the English language pluralisation rules from Inflector.NET (http://andrewpeters.net/inflectornet/). For maximum confidence, feed the result of the above through LightSpeedContext.NamingStrategy,GetTableName -- but unless you have set a custom naming strategy this is a no-op. Obviously we do have this information internally and we'd be open to making it public if there's a use case for it. If you let us know your scenario then we'll have a think about maybe opening up this API in 3.0 or immediately post-3.0. |
|
|
Your comments gave me an idea ;) The case was we have a 'journal' table that records changes to the database, it includes basic information like table name and row id. The goal was to have a generic class where you could just specify the entity type generically and write the journal entry. However, I think we can just modify it to utilize the entity class name instead. Thanks! |
|