So I have created a database and built some things on top. Can I alter the Account modelview and controller so all Identity information adds to my database instead of the default?
-
Which database is used is simply a matter of setting the connection string.Erik Funkenbusch– Erik Funkenbusch2014-02-26 23:06:27 +00:00Commented Feb 26, 2014 at 23:06
-
Thanks, So seeing as I haven't used it yet, If I remove the default string - <add name="DefaultConnection" connectionString="Data and only have <add name="WOMSEntities" connectionString=", surely I need to stipulate which database to use in the controllers etc?user3189899– user31898992014-02-26 23:29:56 +00:00Commented Feb 26, 2014 at 23:29
-
You can just keep the name as "DefaultConnection" and just change the connectionString attribute to your new connection string. If you change the name to "WOMSEntities", you'll have to change the DbContext constructor to use the new connection string name.Anthony Chu– Anthony Chu2014-02-27 00:04:23 +00:00Commented Feb 27, 2014 at 0:04
-
Oh wow that's cool. Then it will script and add relevant tables to my DB? As I said I built this database first and was under the impression that identity was difficult/impossible to implement this way.user3189899– user31898992014-02-27 00:14:18 +00:00Commented Feb 27, 2014 at 0:14
Add a comment
|
1 Answer
Out of the box, you have an ApplicationDbContext defined as such:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
}
To change the connection string, either:
- Change the properties of the existing
DefaultConnectionconnection string in yourweb.config - Add a new connection string in your web.config, and change the
ApplicationDbContextconstructor to pass in the new name.
9 Comments
user3189899
Hi Brendan. Thanks for this. How are the database tables generated etc? When Identity features are first used? Will I have to add these myself? Thanks
Brendan Green
The tables are created in the database via code-fist migrations. You shouldn't need to create them yourself.
user3189899
Thanks. So if I configure it as you stated and register an duff account it will all be generated?
user3189899
how come I now have: private WOMSEntities db = new WOMSEntities(); Error 2 The type or namespace name 'WOMSEntities' could not be found (are you missing a using directive or an assembly reference?)
user3189899
Has the db altered the WOMSEntities db somehow?
|