Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing SimpleMembership with EF model-first
    text
    copied!<p>Can <strong>SimpleMembership</strong> be used with <strong>EF model-first</strong>? When I try it, I get "Unable to find the requested .NET Framework Data Provider" when I call <code>WebSecurity.InitializeDatabaseConnection.</code></p> <p>To put it another way: I can't get the call to <code>WebSecurity.InitializeDatabaseConnection</code> to work when the connection string employs the <code>System.Data.EntityClient</code> provider (as it does when using the <strong>model-first</strong> paradigm).</p> <p>To repro the issue, create an MVC 4 app, and replace the <strong>code-first</strong> UserProfile entity class (which you get for free with the MVC 4 template) with a <strong>model-first</strong> User class that you have created in the Entity Designer:</p> <ol> <li>Create an MVC 4 app in <strong>VS 2012</strong> and add a new, blank Entity Data Model.</li> <li>Add a new Entity named <code>User</code> to the model, with fields for <code>Id,</code> <code>UserName, and FullName</code>. So, at this point, the <code>User</code> data entity is mapped to a <code>Users</code> table and is accessed via a funky connection string that employs the <code>System.Data.EntityClient</code> provider.</li> <li>Verify that the <strong>EF</strong> can access the <code>User</code> entity. One easy way to do that is to scaffold out a Users controller based on the User table and its associated DbContext.</li> <li>Edit the <code>AccountModels.cs</code> file to remove the <code>UserProfile</code> class and its associated <code>UsersContext</code> class. Replace the references to the (now missing) <code>UserProfile</code> and <code>UsersContext</code> classes with references to your new User class and its associated <code>DbContext</code> class.</li> <li>Move the call to InitializeDatabaseConnection from the InitializeSimpleMembershipAttribute filter class to the Application_Start method in Global.asax.cs. While you're at it, modify the arguments to use your new User entity's connection string, table name, and UserId column name.</li> <li>Delete the (no longer used) <code>InitializeSimpleMembershipAttribute</code> class and the references to it.</li> </ol> <p>When you run the repro, it will get an <strong>Exception</strong> at the call to <code>InitializeDatabaseConnection.</code></p> <p>Bob</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload