這是我自己創建的第一個表,我試圖插入數據。將模型與數據庫表關聯以使用EF執行INSERT
問題:在我的控制器中,我不確定如何將模型與實際數據庫表相關聯以執行INSERT
。
而且uc.userId = userId;
我收到以下錯誤:
Invalid initializer member declarato
我創建了這個表的模型:
public class RegisterModel
{
public bool isCertified { get; set; }
public int certType { get; set; }
public string identifier { get; set; }
}
查看:
<tr>
<td style="font-size:10px;">Habilitar Login com Cert. Digital:</td>
<td>@Html.CheckBoxFor(m => m.isCertified)</td>
</tr>
<div id="certDigitalBlock">
<tr>
<td class="smallField">Tipo do Certificado:</td>
<td>@Html.DropDownListFor(m => m.certType, new SelectList(ViewBag.certType, "id","type"))</td>
</tr>
<tr>
<td>Identificação:</td>
<td>@Html.TextBoxFor(m => m.identifier, new { @class = "validate[required]" }) @Html.ValidationMessage("awnserVal", "*")</td>
</tr>
</table>
控制器
using (tgpwebgedEntities context = new tgpwebgedEntities())
{
var userID = from u in context.aspnet_Users where u.UserName == model.UserName select u.UserId;
if (checkIsCertified == true)
{
UsersCertified uc = new UsersCertified {
uc.userId = userId;
uc.certTypeId = model.certType;
uc.keyNumber = model.identifier;
}
context.SaveChanges()
}
}
感謝
問題解決了: http://stackoverflow.com/questions/13641371/entity-has-some-invalid-arguments-when-trying-to-perform-an-insert-with-ef 謝謝大家! –
問題解決了: http://stackoverflow.com/questions/13641371/entity-has-some-invalid-arguments-when-trying-to-perform-an-insert-with-ef 謝謝你們! –