I have found out that SubSonic SimpleRepository expectes plural table names however I have started working on a database that doesn't have this and I am unable to change the table names.
Is there a way I can use Subsonic without making database changes?
I have seen one suggestion but I don't fancy that too much.
I'm not tied to using the SimpleRepository I just thought it would be easiest as I need the ability to swap database connections (SQL & Oracle) based on the clients requirements. The schema is the same on both. With SimpleRepository I can just swap out the connection string in the web.config.
You can apply the SubSonicTableNameOverride attribute on your classes you use with Simple Repo and use an arbitrary table name!
Related
I'm developing an ASP.NET MVC 4.5 project using EF 6 Code First to an Existing Database. I would like to create some new tables with foreign key relationships to one of the tables in the dbcontext I've created. I've altered and added columns in that original table, creating several migrations. There is real data in that table.
I would prefer to create the new tables in the database, but don't see how EF would generate a model for me. I can code the model myself, but don't see any documentation about how I would add it to the context class generated by EF. And then the migrations would be out of whack.
So I'm thinking that the best thing to do would be to delete all the migrations, delete the context class and drop the migrations table. Then I could start from scratch with an initial migration. Am I missing some gotcha? Is there a better way?
FWIW to others facing this dilemma, I figured it out. First I got rid of all the migrations, following the 100+ up-voted answer here: Reset Entity-Framework Migrations
Second, I created new the tables and constraints I needed in the database.
Third, I created a new entity in my solution and generated model classes from the database. I changed calls from the old entity to the new entity.The generator overwrote the model for the original table, but since I have all the annotations in version control, it is trivial to paste them in.
If I need to, I can enable migrations again.
Hope this helps.
Can I prefix all the Liferay tables that it initially creates by doing some configuration changes.
I am new to Liferay and analyzing it for my use.
I gather that new tables being created are prefixed to avoid any conflicts but I have a situation where it suits me better if its other way round.
The answer is no for tables that Liferay creates on its first start. And as you have found yes for newly created tables using servicebuilder(uses the namespace tag)
I am using subsonic simplerepo with migrations in dev and it makes things pretty easy but I keep running into issues with my nvarchar columns that have an index. My users table has an index defined on the username column for obvious reasons but each time I start the project subsonic is doing this:
ALTER TABLE [Users] ALTER COLUMN Username nvarchar(50);
which causes this:
The index 'IX_Username' is dependent on column 'Username'.ALTER TABLE ALTER COLUMN Username failed because one or more objects access this column
Is there any way around this issue?
Which DBMS are you using? Sql Server?
Never had a problem like this with MySQL, but it seems that your DBMS does not allow to alter a column with an index on it. This is not a SubSonic related issue.
Maybe you should do:
Execute("DROP index ...");
AlterColumn("...");
Execute("CREATE index ...");
It is one or the other. If you choose to manage your DB by Subsonic (use migrations), you can't use indexes and stuff. Sorry mate.
I have a SQL server with 50 databases. Each one has the exact same schema.
I used the awesome Subsonic 2.2 create the DAL based on one of them.
I need to loop though a list of database names and connect to each one and perform an update one at a time.
If there a way to alter how subsonic uses the connection string. I believe I would need to store the connection string in memory that way it can keep changing.
Is this possible?
I tried doing a
ConfigurationManager.ConnectionStrings["theConnStrName"].ConnectionString = updated-connection-string-here;
.. but that did not work
thanks!
Subsonic was designed primarily for one database only.
I've done multiple databases a couple of ways. I had posted a complete sample for creating providers on the fly in the old forums for subsonic. Those posts are gone now. What you can try is set up one provider in the config file (yourProviderName) with a dummy connection string just to initialize subsonic, then set the actual connection string as needed in your code. This only works with one database at a time but I think this is what you needed. If you want to use multiple databases at the same time, and involves more code and some changes to the subsonic 2.x core.
DataProvider provider = DataService.GetInstance(yourProviderName);
foreach(string connString in connectionStrings)
{
provider.DefaultConnectionString = connString;
DataService.Provider = provider;
// ... do stuff
}
I don't think it's easy to fix without creating a SubSonic provider for each database.
Instead I would put the SubSonic-source as a project in the solution and debug my way to the best and most clean place to extend the code wwith some sort of connnection string dictionary list and functionality to set the one you want at a given time.
I have a data model that includes common columns like addedBy, editedby (user), addedDate, editedDate.
Is there a setting I can use in SubSonic 2.1 that will automatically update these fields appropriately instead of having to explicitly specify in every update?
Check out http://subsonicproject.com/setup/subsonic-conventions/. SubSonic uses a convention-based approach when it comes to audit columns. If you can change your column names to CreatedBy, ModifiedBy, CreatedOn, and ModifiedOn respectively, then they will be updated automatically. I don't think there's a way to change what those names can be without making changes to the SubSonic source code.