I have an application that needs registration of profiles (lastname, firstname, birthdate, address, ...). When using a Starter Site template (with the UserProfile table) I'm considering to add my additional fields into a separate table (leaving the UserProfile
table as-is) and using the UserId column of the UserProfile table as a foreign key in my additional table.? Or should I add all columns/fields to the UserProfile table?
Being that I prefer database normalization, you are best off creating the second table and storing your additional details there. Simply refer to the ID number as a foreign key in the UserProfile table and that should tie the two together.
Mark as answer posts that helped you.
Marked as answer by gdillen on Nov 09, 2012 06:01 PM
Yes, you are correct, however it seems the original poster might be uncomfortable doing it that way. Its more or less personal choice. There is no rule saying you can't, because yes you can.
Since I don't see any connection string entry in web.config I suppose WebMatrix automatically looks for a "StarterSite" database?
When using fullblown SQL Server I suppose I have to adapt all existing pages (register.cshtml, ...) with the new database name as well as creating a connection string in web.config?
Creating a second table that will inevitably have a one-to-one relationship with the first table is not a prime example of normalisation in my opinion.
Since I don't see any connection string entry in web.config I suppose WebMatrix automatically looks for a "StarterSite" database?
The Web Pages framework will first look for a database file in App_Data with the name that's passed in to the InitializeDatabaseConnection method. If there isn't a databse file, it looks in the connectionsstrings section of the web.config for a connection
string with a matching name.
gdillen
When using fullblown SQL Server I suppose I have to adapt all existing pages (register.cshtml, ...) with the new database name as well as creating a connection string in web.config?
You will only have to make changes where a database connection is opened - unless you name your connection string "startersite". And yes, you need to add a connection string.
gdillen
Member
99 Points
93 Posts
Starter Site Registration
Nov 09, 2012 05:38 PM|LINK
I have an application that needs registration of profiles (lastname, firstname, birthdate, address, ...). When using a Starter Site template (with the UserProfile table) I'm considering to add my additional fields into a separate table (leaving the UserProfile table as-is) and using the UserId column of the UserProfile table as a foreign key in my additional table.? Or should I add all columns/fields to the UserProfile table?
Thanks.
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Starter Site Registration
Nov 09, 2012 05:58 PM|LINK
Being that I prefer database normalization, you are best off creating the second table and storing your additional details there. Simply refer to the ID number as a foreign key in the UserProfile table and that should tie the two together.
ayanmesut
Member
219 Points
85 Posts
Re: Starter Site Registration
Nov 09, 2012 06:04 PM|LINK
you can add more fields to the UserProfile table.
gdillen
Member
99 Points
93 Posts
Re: Starter Site Registration
Nov 09, 2012 06:05 PM|LINK
Thanks.
One additional related question: what should I do to have my UserProfile table in SQL Server instead of SQL Compact?
Thanks.
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Starter Site Registration
Nov 09, 2012 06:09 PM|LINK
Yes, you are correct, however it seems the original poster might be uncomfortable doing it that way. Its more or less personal choice. There is no rule saying you can't, because yes you can.
bbcompent1
All-Star
33097 Points
8529 Posts
Moderator
Re: Starter Site Registration
Nov 09, 2012 06:11 PM|LINK
You can use MS Web Deploy to handle that.
http://erikej.blogspot.com/2011/03/migrate-sql-server-compact-database-to.html
Mikesdotnett...
All-Star
154951 Points
19870 Posts
Moderator
MVP
Re: Starter Site Registration
Nov 09, 2012 06:15 PM|LINK
You pass the name of the connection string to the first parameter of the WebSecurity InitializeDatabaseConnection method.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
gdillen
Member
99 Points
93 Posts
Re: Starter Site Registration
Nov 09, 2012 06:23 PM|LINK
Since I don't see any connection string entry in web.config I suppose WebMatrix automatically looks for a "StarterSite" database?
When using fullblown SQL Server I suppose I have to adapt all existing pages (register.cshtml, ...) with the new database name as well as creating a connection string in web.config?
Mikesdotnett...
All-Star
154951 Points
19870 Posts
Moderator
MVP
Re: Starter Site Registration
Nov 09, 2012 06:31 PM|LINK
Creating a second table that will inevitably have a one-to-one relationship with the first table is not a prime example of normalisation in my opinion.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
Mikesdotnett...
All-Star
154951 Points
19870 Posts
Moderator
MVP
Re: Starter Site Registration
Nov 09, 2012 06:37 PM|LINK
The Web Pages framework will first look for a database file in App_Data with the name that's passed in to the InitializeDatabaseConnection method. If there isn't a databse file, it looks in the connectionsstrings section of the web.config for a connection string with a matching name.
You will only have to make changes where a database connection is opened - unless you name your connection string "startersite". And yes, you need to add a connection string.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter