0
votes

Ihave a DB First EF5 project that I am implementing SimpleMembership in. I have most of it working, but a question has come up.

The main User table created by Simple Membership has the UserName in it. I have a couple other places in the app where I need to query this table, specifically the userName. Simple Membership does not use the Data.EntityClient in the connection string, so i have it set to the SqlClient.

So because i don't have an entity model with the provider User table, I am not sure how to query it. Usually i would create an instance of the entity model and use LINQ on it, but when I try it I get a very long winded error about mixing code first with entity first. I have modified the 'initialSimpleMembershipAttribute' so it points to the separate connection string I made for the Membership tables.

One solution i thought of was to save the user, then copy the username to one of my custom tables, then i can query it through EF, but this seems like it would violate some kind database 'best practice' of duplicated data.

Another idea I had is to create a second edmx model for the tables that Membership created, but if SimpleMembership does not use the EntityClient, does that also mean it will not recognize a entity model?

1

1 Answers

0
votes

You're way over complicating things.

If you have your own model, then you can just get rid of the model that the default template gives you, and use yours instead. It doesn't matter if it's Code first or database first or whatever. Just change the Initialize SimpleMembershipAttribute to remove the references to the default model they give you, and make sure you modify the InitializeDatabaseConnection call correctly.

WebSecurity.InitializeDatabaseConnection("YourConnection", "WhateverYouCallYourUserTable", 
    "WhateverYourUserIdIs", "WhateverYourUserNameColumnIs", autoCreateTables: true);