I believe I want to do a update query.
I've found a tutorial that introduces me to ASP.Net membership where I can use an Access provider to fill my database needs. However, I have an existing Access database of customers, but I do not know how to copy this existing database into the new ASPNetDB.mdb. It's identical to the SQL provider as far as I know.
Every table is related to each other so I cannot enter new records. I've wanted to append the UserName column, the passwords, email's, and a new field to the new ASPNetDB.mdb. How would I go about doing this?
So instead of having to copy records from one database to another database why don't you just create a custom membership provider and use the same existing database.
Basically you create a class that inherits from the MembershipProvider class and you implement all the methods from the MembershipProvider class. I.E. ChangePassword, CreateUser, DeleteUser, etc... In your implementation you write custom code to access the tables that already exist.
This way you can keep your current database and still use ASP.NET membership.
Here is an MSDN article with a sample implementation.
Sample Membership Implementation
As suggested, if the table structures ARE the same, then why not just make a copy of the original database and re-name to the same as your ASPNetDB.mdb.
If you're looking to import older data, then again simple open ASPNetDB.mdb with Access and import the data + tables from the older database. Access can and WILL import the tables and WILL ALSO BRING IN related data tables. This will create new local tables, but then again you stating they are the same. (so delete the existing tables in ASPNetDB and import the other ones).
You can ALSO import the table data into existing tables if they are empty. So assuming empty tables, then a compact + repair will re-set auto numbers, and then you can link to the older database and use append quires. I would only do this if a few tables. You have to import the "parent" tables first if referential integrity is enforced as it makes little sense to add child records first!
However I fail to see why not just making a whole copy of the older existing database and re-naming it as ASPNetDB would not work if your claim of the tables being the same in both.
Related
I have an EF6 Database First application that uses tables generated to an edmx from the dbo schema.
To update certain large pricing tables that work in concert with each other, I create new tables in a new schema based on the date, then inside a transaction, move the current tables to a backup schema, and move the new tables to the dbo schema. This is implemented using a new MetadataWorkspace created by reading the edmx file and changing the schema, and allows me to have two DbContexts where one works with the existing data in the dbo schema, and the other works with the new tables in the new schema. And works great for Database First!
See this SO article.
For CodeFirst, one can set the modelBuilder.HasDefaultSchema in OnModelCreating, but then the DbContext is locked down, and OnModelCreating is not called again for new DbContext instances, so whatever schema was set is now used for all such DbContexts for the duration of the application.
My question is – how can I dynamically change the DbContext with CodeFirst where I can have two DbContext, each using different schema? I cannot just define two DbContext derived classes since the schema name is dynamic.
Apparently this cannot be done but once since the DbContext is locked down and keeps the schema name. I plan to address this need by keeping the second schema name fixed rather than dynamic. Would be nice if could "clone" the locked down DbContext with a new schema name but currently not possible anyway that I have found. Closing.
You can set the the schema dynamically in EF6. You need to adjust the way you initialize your DBContext though.
I found most of what I was looking for here:
Multi-Tenant With Code First EF6
a customer has an existing database. The schema is often changed within the database itself (e.g. he adds a new column).
My task is to develop an admin area with symfony that automatically reacts on table schema changes without modifying the application code. E.g. the customer adds a new column to table "MyEntity", and the application automatically generates a new column in the accordingly list view.
My approach is to dynamically map the table columns to the Entity class so that ALL Attributes and ALL Getters/Setters are generated dynamically from the table schema.
So is it possible to map the table columns in a Doctrine Entity without the use of Annotations or XML Files.
Something like:
class MyEntity{
public function generateMappingFromSchema($sTableName){...}
}
Please don't do that. Doctrine was not designed for such use case.
There is a library though you should check https://github.com/laravel-doctrine/fluent which basically is a mapping driver that allows you to manage your mappings in an Object Oriented approach. And there are other tools:
http://crud-admin-generator.com/
http://crudkit.com/
http://www.grocerycrud.com/
which are maybe better for that, I don't know.
But again, please don't do that. Do not allow the customer to modify the database schema or give them e.g. a phpMyAdmin which was designed for that.
I have found many tutorials for adding columns to the Identity tables (which I have successfully moved to the application database) with database migrations however my understanding is this is not applicable in database fist projects. So...how do I add columns to the aspnetusers table in a database first project?
I would like to ad a bit type column called Is RegComplete which is initially set to 0 then at some point when the user has completed some more tasks then set to 1.
OK, I've cracked it! Firstly I didn't realise that although I have moved the Identity tables to the Application database there is still two Database Contexts, one for the application tables which are DB First, and the other for the Identities tables.
I was able to enable migrations and add the column using code first and migrate then update the database. The new column is now available in the controller.
I found this tutorial which helped me: http://blogs.msdn.com/b/webdev/archive/2013/10/16/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates.aspx
The easiest solution:
Add columns into AspNetUsers table
Add properties into IdentityModels.cs class (Check attachment)
Add same properties into AccountViewModels.cs\RegisterViewModel class
Compile and it will work.
Attachment
(VS 2017, MVC5)
I have a application which I would like to add custom fields to the users table. I am not sure how to work after adding the columns. The columns are foreign keys to another table which holds more details for the user.
I am using Linq-to-SQL. So every time I add a user (using the membership functions i.e. Membership.CreateUser(..)) I end up calling another service to update the foreign keys on the users table.
Any better way of doing this will be highly appreciated.
Why are you adding foreign keys to the User table, pointing to another table with additional info??
I would do it the other way around:
create your own table UserInfo
create a FK column in UserInfo that points to the row in your ASP.NET membership User table
leave the system-provided User table alone - so you won't run into problems when e.g. an upgrade to the ASP.NET membership system is rolled out.....
I strongly recommend you not to extend secure tables such like Users, Membership, Profile. Better create another one table in your database (not secure database) with full info which you need. Call it 'User' with foreign key to 'Id' of table User in secure database.
I'm using default membership class in my website. But I'm a little confused with the complex database design of the ASPNETDB.
Let's say I want to add details about user like name, surname, address etc... Where should I put them aspnet_Membership table or aspnet_Users table and why? I mean I can see that I should put the details on aspnet_Membership. But then again why there is two of them and the bindings on aspnet_Users...
Or lets say I'm adding a messaging into that which table should I key to, for the user details?
I'm confused and I would be appreciated if you can tell me the use of these two tables.
Here is the diagram for the default ASPNETDB which you should probably have:
Rather than modifying the built in ASP.NET membership schema, you can use ASP.NET profiles to store custom properties about your users. Here's one tutorial on the subject.
You can add the profile tables to your schema using aspnet_regsql.exe (which you're probably already familiar with, given that you have already generated most of the schema). Use the -R p switch to get the profile tables/procs.
If you want to connect your custom table to ASP.NET membership, use UserId as foreign key from aspnet_Users table rather than aspnet_Membership table to your custom table. For reference, please note how aspnet_Profile or even aspnet_Membership is using UserId as foreign key from aspnet_Users table.
Please see the database diagram here:
http://msdn.microsoft.com/en-us/library/Aa478948.asp2prvdr0102l(l=en-us).gif
Good luck ...
I would advise not to alter any of the tables provided by the ASP.NET membership schema. To store additional data use the already mentioned ASP.NET profiles option or create a custom one which maybe fits your bill beter.
The reason why there are two tables for storing user data is already answered over here.
Good luck which choosing the right solution.