Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Idea to make Massive even less...er...Massive #79
I've been playing with including some sort of dynamic Database/Repository class such as below:
This eliminates having to create new Model classes that derive from DynamicModel for each table in your database.
Using Database.Default makes some assumptions:
Great convention over configuration approach.
You could also call:
I don't really like this last one above because it could get messy dragging that around everywhere, but maybe a simple fluent interface for one-time registration/mapping would work. Maybe something like:
From then on any call to Database.Default.Products would create a new DynamicModel using "tblProducts" as the table name and "ProductID" as the primary key field.
Maybe even something similar to register your default connection string too. Something like:
Curious to get your thoughts?
Here's the class I'm using and it works quite nicely. For DI/IoC, simply add an interface that defines the Default property and Open method.
This comment has been minimized.
This comment has been minimized.Show comment Hide comment
Database.Open() does this already yes? Also - the idea of having a class is that it provides you a TableName, PrimaryKey and so on - this is handy if you don't want to write SQL. Appreciate the suggestion but I think I'll keep it the way it is - another reason is that I'm adding in validators and callbacks :)