I chose to use mongodb
as a storage for domain-centric data.
I was searching for official mongodb providers
to integrate them into ASP.NET MVC
project to keep a single application database. There are no official providers and available ones don't look mature/stable. So I decided to use simple membership as it is.
How to get rid of Entity Framework
-specific code, if possible, from the AccountController
?
How would you manage user profiles having both SimpleMembership UserProfile
and MongoDB
User
?
Example
In a separate assembly [project-name].domain
there are two classes:
public class Event {
public DateTime ScheduledDate { get; set; }
public String Name { get; set; }
public Location Location { get; set; }
}
public class User {
public String Name { get; set; }
public List<Events> AssociatedEvents { get; set; }
}
Will this be a solution if I add an UserProfileId
to User
?
public class User {
public Int32 UserProfileId { get; set; }
public String Name { get; set; }
public List<Events> AssociatedEvents { get; set; }
}
you have to use connectionString from an appSetting.
You will need to download the above fork, build & change your existing dll reference to use the new dll.
Then...
Use your config:
<appSettings>
<add key="MONGOLAB_URL" value="mongodb://localhost/ASPNETDB"/>
</appSettings>
... the above value will get replaced by appharbor/mongolab (and if you have other parts of the app that work, then this is correct)
<providers>
<clear />
<add name="MongoDBMembershipProvider" type="MongoDB.Web.Providers.MongoDBMembershipProvider"
applicationName="/" appSettingsConnectionStringKey="MONGOLAB_URL" collection="Users"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" />
</providers>
So in the above config, it has the appSettingsConnectionStringKey parameter. The code within the customised provider, reads the appSettingsConnectionStringKey value 'MONGOLAB_URL' and then uses that to read the ConfigurationManager.AppSettings["MONGOLAB_URL"] and it obviously, MUST match the appsetting Key name above.
[1]: https://github.com/osuritz
[2]: https://github.com/osuritz/MongoDB.Web/commit/b1e9534023ca8cb2e74eb1adbdcb1cd7dd693efa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With