I have an Entity Data Model for my Web Site that includes a table with some extra data for the registered users (called UserInfo). Currently, I'm setting the id of the new rows of UserInfo using the Membership.GetUser(...).ProviderKey.
What I want to do is to add a navigation property to my UserInfo table to point to the corresponding Membership row for that user but, due I have not the Membership schema in my Entity Designer, I can't figure out how to stablish this link between the tables.
Any idea?
Thanks very much,
Well, I've finally decided it's easier simply to add a property to my UserInfo table (called guid) that store the guid of the MembershipUser schema.
Related
I'm purposely not posting any code here as I'm really just looking for some guidance to the following problem:
I have created a three new fields in my AspNetUsers table - FirstName, LastName, and NickName. I also created a composite key using those three fields. When I try to create a new user that has all three of these fields the same, the application throws an error as expected when the unique rule is violated.
I would like it to simply post back to the Register User form indicating that the NickName must be changed to something else.
Do I need to implement a Custom User Store? Is there a simpler way?
Thank you for any suggestions.
I am creating ASP.NET Dynamic Data Site (using entities) to manage master tables of my application.
All my master table has a Primary Key of "UniqueIdentifier" in SQL Server. Where should I write "Guid.NewGuid()" in order to give default value (as new Guid) and to show them in textboxes bound with these fields?
ok, I found the solution myself.
We need to open EDMX file, and ID property in each entity needs to be have StoreGeneratedPattern="Computed"
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 have 3 tables(Roles,Actions and RoleActionLinks). Roles table has few columns(RoleID,RoleName,Desc). Actions table has few colums(ActionID,ActionName,Desc). In RoleActionLink is created for store the association between Roles and Actions and this table has the columns such as RoleID,ActionID
When I created the data model(edmx). it shows only Role and Action as entity. i did not find RoleActionLink table. but even there is no direct relation between Roles and Actions table, both tables are automatically related using RoleActionLink table.
When i create the new Action, a action record should be populated in Action table(this is works fine). At the same time, i need to populate record in RoleActionLinks table. But i dont have the entity to populate.
Please tell me how to accomplish my needs.
This should work:
newAction.Roles.Add(role1);
newAction.Roles.Add(role2);
Look at navigation properties in your model. There should be EntityCollection called Roles (name may differ).
Entity framework automatically handles n-n tables and creates collections on both sides.
My table, AccLink, has a foreign key, UserId, to the aspnet_User table created by the Membership Provider.
When creating an object of type AccLink (I'm using the entity framework) I need to assign the aspnet_User by getting the current user object.
I tried Membership.GetUser(userName) but it said it couldn't be converted to type aspnet_User. What is equivalent to the model built by the entity framework that I can use to assign to the AccLink object?
I think the only way is to get an aspnet_User object from the database (e.g. select by user name or email or some unique info you get from MembershipUser)
How are users authenticating? If you're not using forms based authentication then System.Net.CredentialCache.DefaultCredentials would hold the current security context.