So first of all I dont know what Entity Framework version I am using. I am assuming its 4 but how do I check?
Second i have the following connection string in web.config:
<connectionStrings>
<add name="DBEntites"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
As you can see they are the same DB. In fact they are the DB created by asp.net Membership Provider.
Now I have the following Model:
public class Profile {
[Key]
public string username { get; set; }
[Display(Name = "Full Name")]
public string FullName { get; set; }
}
Simple enough?
Then I have the following class that connects to the DB:
public class DBEntities : DbContext {
public DbSet<Profile> Profiles { get; set; }
}
Then in my Account Controller, infact this is the same controller created by the VS2010 when you choose a new MVC3 project.
[HttpPost]
public ActionResult Register(RegisterModel model) {
if (ModelState.IsValid) {
// Attempt to register the user
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
Profile pm = new Profile();
pm.username=model.UserName;
pm.FullName="unknown";
db.Profiles.Add(pm);
db.SaveChanges();
if (createStatus == MembershipCreateStatus.Success) {
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
return RedirectToAction("Index", "Home");
} else {
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
SO when i run this application, it runs through without exceptions. If I add a new user, the new user is added to the asp.net membership tables. So from my understanding the Entity framework should create a table called "Profile" with the two columns "username" and "fullname".
However, it dosn't. Why is it the code can step through without exceptions, the db.SaveChanges()
can go through, yet there is not table created?
What am I doing wrong?
edit: I think the table is there beause if I try to create an entry with the same username (obviously can't since its a Primary Key), it throws an exception saying the entry already exists.
BUT I cant seem to find the table!