1
我已經爲ApplicationUser添加了一些屬性,其中兩個屬性是ICollection的屬性。 當我使用Update-Database時,它不會爲這兩個成員生成列。ApplicationUser ICollection成員未被保存在數據庫中
那麼,我在這裏錯過了什麼?我想這是非常基本的。我習慣於在Java中使用Hibernate,在那裏爲元素集合生成一個新表。
一些代碼樣本 -
ApplicationUser
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
public byte[] UserImage { get; set; }
public virtual ICollection<string> Interests { get; set; }
public virtual ICollection<string> Friends { get; set; }
}
RegisterViewModel
public class RegisterViewModel
{
[Required]
[Display(Name = "Username")]
public string UserName { get; set; }
[Required]
[StringLength(25)]
[Display(Name = "First Name")]
public string FirstName { get; set; }
[Required]
[StringLength(25)]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Display(Name = "User Image")]
public int UserImage { get; set; }
[Required]
[Display(Name = "Interests")]
public virtual ICollection<string> Interests { get; set; }
[Display(Name = "Friends")]
public virtual ICollection<string> Friends { get; set; }
//........
任務寄存器(RegisterViewModel模型)
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser()
{
UserName = model.UserName,
FirstName = model.FirstName,
LastName = model.LastName,
Interests = model.Interests,
Friends = model.Friends
};
HttpPostedFileBase file = Request.Files["file"];
byte[] imgBytes = null;
BinaryReader reader = new BinaryReader(file.InputStream);
imgBytes = reader.ReadBytes(file.ContentLength);
user.UserImage = imgBytes;
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
//............
這樣做。謝謝! – omm118