Setting up SubSonic with Databases other than SQL Server - asp.net

I am currently using SubSonic (2.2 and 3) for some ASP.NET projects and have managed to get them working with SQL Server (using ActiveRecord). However, I also want to know how to set it up with other (open source) databases, e.g. PostgreSQL and SQLite. This is so I can use it on a web host without SQL Server on. The providers I have found are:
PostgreSQL: Npgsql
SQLite: System.Data.SQLite or Mono.Data.SqliteClient (if it works with Microsoft.NET)
Anyone have any experience with SubSonic know how to do this (some sample demo would be good - just a basic primer on querying would be fine)? Non-ASP.NET MVC though (not got into it yet). I have only basic knowledge of SQLite (basically using SQLite Manager in Firefox and querying it via PHP Data Objects) and have not used Postgresql, but assume it would be more scalable than SQLite.

For version 3
PostgreSQL: There aren't any templates for postgres at the moment so you'd need to create the templates yourself
SQLite - The steps should be as follows:
Add a reference to System.Data.SQLite
Look in the TemplateProviders folder you'll find a SQLite.ttinclude which you'll need to drop into your project instead of SQLServer.ttinclude.
Change the .tt files that reference SQLServer.ttinclude to reference SQLite.ttinclude instead.

This is so I can use it on a web host without SQL Server on.
With the release of SQLExpress dont all hosts offer this? (I only use dedicated server so I have no direct experiance with this)
In response to your question.
SQLite - http://codefornothing.wordpress.com/2007/07/19/sqlite-data-provider-for-subsonic-part-2/
Postgre: Doesnt look as simple,
Subsonic postgreSQL Template
PostgreSQL via subsonic
Good luck.

In short, Subsonic only support few database only NOT ALL ( that what their claimed :( ). Try nHibernate, support most of the database.

Related

EntityFramework 7 - CodeFirst - SQLite - Manage DB using ApplyMigrations at runtime

I am well on my way to utilizing EF7 CodeFirst with SQLite...but really want to employ DB Migrations at runtime. This is a desktop application (Click-once deployment) meant to sync with a main database when connection is available, and provide offline data when no connection is present.
I have pulled down the nuget pre-release versions and all is working, except I cannot find any documentation of how to apply the migrations at runtime. I can successfully Add-Migrations and manually Apply-Migrations...but need a way to programatically Apply-Migrations at runtime.
I've also browsed the EF7 open-source project, but could not get anywhere there.
Versions I'm using: Latest Pre-release as of 9/15/2015
EntityFramework.Sqlite v7.0.0-beta7
EntityFramework.Relational v7.0.0-beta7
EntityFramework.Commands v7.0.0-beta7
...et al...you get the picture.
I am asking for help to apply runtime migrations...or what is the documented/recommended path for programatically maintaining a local/embedded db using EF7 CodeFirst SQLite?
UPDATE:
I went back to EF6 with SQLite but then found out that there is not SQLMigrationGenerator for SQLite.
EDIT:
I believe ApplyMigrations() method referenced in one of the notes has been deprecated. Searching the repository, there is no reference to "ApplyMigrations".
Today you can invoke the extension method Migrate on the DatabaseFacade.
This method is only available when the using Microsoft.Data.Entity statement is present. It comes from the RelationalDatabaseFacadeExtensions class that is part of the EntityFramework.Relational package.
Still have to find out how to migrate up and down from the API.

How do i update an existing database to support ASP.NET Identity 2.0

I have a web solution that I upgraded to ASP.NET Identity 2.0. The problem i now face it that i have some solutions of this software running in production at several customers. When I try installing the new software (with ASP.NET Identity 2.0) on the existing database (full of their data). I then get an error: "The model backing the "ApplicationDbContext" context has changed singe the database was created"
How do i update the database in the existing solution to a database that fits the new ASP.NET Identity? I looked at the ASPnetUsers table and there has been added several new columns.
Is there a way to disable this check? Or is there a way to fix it?
Personally, I would create a new project/database containing just the ASP.Net Identity 2.0 features and create a dummy user (just to make sure that it all works correctly).
Then, use schema comparison between the new database and your existing database. You can then generate scripts to create the user tables in your customers' database.
You may still have further integration work to do, but it should get you over the hump.
I suppose you don't use EF code first. You could run your project in dev using code first and get the full DB structure including the Identity tables, then compare against the prod schema and implement the differences.
This should give you the hint:
http://blogs.msdn.com/b/webdev/archive/2013/12/20/updating-asp-net-applications-from-asp-net-identity-1-0-to-2-0-0-alpha1.aspx

Subsonic SQLite Multiple Files

I have an application that must be accessed for many users.
To optimize the performance I intend to store each user profile information at a independant database file.
I need everytime a user login the application, to setup a new provider linked with his own database.
All databases have the same structure. So while querying user the commom generated DAL classes must switch for the database file relative the the user.
Is there a way for configure SubSonic for doing that switch at runtime?
Thanks.
Well, assuming we 're talking about SubSonic3:
I have made a patch for this and logged it as an issue in the SubSonic Templates project on github, where the source is available. You can find the issue (and a link to the code) here.
After you apply the patch, you will have a new DefaultDataProvider property which does exactly what you want. Use it like this (e.g. after a user logs in):
YourSubSonicGeneratedNamespace.YourDatabaseName.DefaultDataProvider =
SubSonic.DataProviders.ProviderFactory.GetProvider(
"your connection string here",
SubSonic.DataProviders.DbClientTypeName.SqlLite);
And you 're good to go.
For SubSonic 2, this answer sounds like what you want.
With subsonic 2 I use an approach where I inject the provider at runtime rather than loading it from the app.config file.
Look at my answer here: Subsonic in a VS2008 Add-In woes
Instead of just using one provider you could create one for every user who starts the application and change the default provider as needed.

How to generate entity framework model from client side?

Can I generate entity framework model by clicking button in browser in client-side and save it back to web server PC?
EdmGen is the way to go if you're sure this is the best solution to your problem: http://msdn.microsoft.com/en-us/library/bb896270.aspx
If you're having problems with it could you please post the command line arguments you're using to call it?
You'll have to create a process in your web app (System.Diagnostics.Process) in order to kick off the executable from the browser side.
As David Neale says EmdGen is an option, if that is really what you want.
There is also EmdGen2, which has the advantage that it is able to work directly with the Edmx file:
EdmGen2 is a command-line tool for the
Microsoft ADO.NET Entity Framework.
The tool can be used as a replacement
for the EdmGen.exe tool that ships
with the .Net framework 3.5 SP1.
EdmGen.exe can only read and write the
CSDL, SSDL & MSL file formats.
However, EdmGen2.exe can read and
write the EDMX file format used by the
Visual Studio design tools.
Additionally, EdmGen2.exe can
translate between EDMX and CSDL, SSDL
& MSL formats, and the source code can
act as examples on using the tooling
APIs defined in the
System.Data.Entity.Design assembly.
Additionaly, EdmGen2.exe contains some
experimental functionality not found
in EdmGen.exe. Ankit Malpani, an
intern with Microsoft Research in
summer of 2008, and James Terwilliger,
a Post Doc researcher with MSR,
updated EdmGen2.exe with the ability
to identify inheritance
relatationships in relational database
schema. You can access this
functionality by using the
"RetrofitModel" option. The
RetrofitModel option connects to a
database instance and constructs an
EDM model (csdl, msl, ssdl, and edmx
files) that includes inheritance. The
tool uses data mining techniques to
identify TPT and TPH patterns in the
database instance, as well as vertical
partitioning, and constructs a
suitable model and mapping. To use the
tool, launch EdmGen2 with the
following arguments:

Active Record and Linq T4 Templates problem

I've started a C# web application project using subsonic 3.0.3 as my DAL and SQLite for database.
It doesn't have any problem when using SimpleRepo, but the problem occurs when I try to use ActiveRecord/Linq T4 templates.
It says "Metadata file 'System.Data.SQLite' could not be found". The settings.ttinclude is the one provided with SQLite.ttinclude file and its config looks ok, and other files are instructed to use SQLite.ttinclude of course. I've also tested them with an SQL Server database and everything goes fine.
Also tried searching about it on the net and all I could find were these:
Subsonic Google Groups which instructs me to add a reference to System.Data.SQLite to the top of settings.ttinclude. No luck.
Someone at here commented about this issue, and it was answered to check the connection string, which doesn't seem to be my problem, because the app works when I use SimpleRepo.
Is SQLite installed on your machine? You need the .NET driver for it as well (that's what can't be found).

Resources