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
|
I'm in the process of building an application where much of the data access will be dynamically handled and I need to have access to a few pieces of database schema information at runtime. Basically the issue here is that there's a generic data layer in the app that doesn't know about the Model structure so it has to do a few things purely dynamically. What I'm after specifically are the name of the underlyhing table and PK so both can be accessed via strings at runtime. Preferrably accessible all through strings or if necessary based on an entity type reference. I can't seem to figure out how to get underlying schema information for the database with Lightspeed. Is this possible? +++ Rick --- |
|
|
Hi Rick, We do keep track of this internally (known as the Type/Field model) but it is not something we expose publically since its not expected to be something you would want to know since you are programming against a domain model :) While not neccesarily desirable, you could craft a solution around the fact that LightSpeed is convention based and the name for your tables will be the same as the entity type (or its plural form if that configuration switch is enabled on the context) unless a TableAttribute is present on the class. Likewise fields have a Column attribute if the name is being overridden. This essentially would mimic the same mechanics LightSpeed uses within its internal model to determine what the appropriate table/column names are when emitting SQL.
Jeremy |
|
|
Thanks Jeremy, Unfortunately that makes Lightspeed very static and very difficult to build a generic and reusable layer around since there apperars to be no way to create queries dynamically. Either from SQL or through any language based mechanism. A generic layer wouldn't know abou the structure of the model so it can't make assumptions about the database - it has to know a few things. Along the same lines it's quite useful (as in Linq to SQL) to have access to meta data as well as to the underlying provider for those cases when LINQ and the object model are actually inefficient (set update operations usually). I really like what I see in Lightspeed's entity and modelling stuff in the designer as well as the migrations stuff, the easy multi-provider support but unfortunately the inability to get dynamic access for me is a deal breaker. Thanks for your help tho - appreciate the quick response, Aloha, +++ Rick --- |
|
|
Pardon my intrusion, looking at the initial requirement, I think there is a way to get the table name info dynamically. Basically, the idea is getting attributes of entity type via reflection. We use code similar to this: If there is no attribute, the tableName and entity type name is the same, but we switch to uppercase as we have Oracle DB underneath. Not sure about getting PK name though, but I guess if it is somewhere in Lightspeed model attributes, it could be fetched via reflection. Though, I hope I am not missing the point of the requirement. P.S. Rick, I really like your blog :) |
|