去這是我的控制器我的代碼:如何測試,如果我的LINQ查詢通過
MGEntities db = new MGEntities();
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
if (createStatus == MembershipCreateStatus.Success)
{
FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
MembershipUser myObject = Membership.GetUser();
Guid UserID = (Guid)myObject.ProviderUserKey;
MyProfile profile = new MyProfile();
profile.Address = model.Address;
profile.City = model.City;
profile.Zip = model.Zip;
profile.State = model.State;
profile.UserId = UserID;
Debug.Write(profile.State);
db.aspnet_Profiles.Add(profile);
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
}
}
這是我的我的資料類:執行LINQ查詢
namespace MatchGaming.Models
{
[Bind(Exclude = "ProfileId")]
public class MyProfile
{
[Key]
[ScaffoldColumn(false)]
public int ProfileId { get; set; }
public Guid UserId { get; set; }
[DisplayName("Address")]
public string Address { get; set; }
[DisplayName("City")]
public string City { get; set; }
[DisplayName("Zip")]
public string Zip { get; set; }
[DisplayName("State")]
public string State { get; set; }
}
}
後,我查看我的數據庫並沒有添加任何內容我正在爲我的實體使用POCO。這裏是我的課:
namespace MatchGaming.Models
{
public class MGEntities : DbContext
{
public DbSet<MyProfile> aspnet_Profiles { get; set; }
}
}
我基本上只是不明白爲什麼它不添加到數據庫中,如果那裏有一個方法可以讓我檢查,如果查詢經歷了正確與否,或者如果任何人都可以看到這個問題。謝謝!
你試過調試器嗎? – SLaks 2011-03-15 03:49:12
是的,我調試,並沒有錯誤 – anthonypliu 2011-03-15 04:00:20