2012-11-30 2 views
0

EF를 사용하여 삽입 문을 수행하는 방법을 찾을 수 없습니다.EF로 INSERT를 수행하려고 할 때 엔티티에 잘못된 인수가 있습니다.

많은 오류가 발생했습니다.

코드는 모두 여기에 있고 문제가 컨트롤러입니다 : 난을 벌써 시도 :

context.sistema_UsersCertified.Add(uc); 
context.Set<sistema_UsersCertified>().Add(uc); 

이 sistema_UsersCertified 일부 무효 argumments

이유

을 가지고 있다고?

내 dbcontext입니다 :

public partial class tgpwebgedEntities : DbContext 
{ 
    public tgpwebgedEntities() 
     : base("name=tgpwebgedEntities") 
    { 
    } 

    protected override void OnModelCreating(DbModelBuilder modelBuilder) 
    { 
     throw new UnintentionalCodeFirstException(); 
    } 

    public DbSet<sistema_UsersCertified> sistema_UsersCertified { get; set; } 

} 

이 표는 4 Collumns는있다 : 아이디 (INT), 사용자 ID (GUID), certTypeID (INT), keyNumber (문자열) 그래서

을 해당 테이블에 기반을 둔 모델 만들었습니다

public class UsersCertified 
{ 
    public Guid userId; 
    public int certTypeId; 
    public string keyNumber; 

    public UsersCertified(Guid uId, int ctId, string kn) { 
     userId = uId; 
     certTypeId = ctId; 
     keyNumber = kn; 
    } 
} 

을하고 난 viewtha이 t은 컨트롤러에 데이터를 전송 :

<table> 
        <tr> 
        <td style="font-size:10px;">Habilitar Login com Cert. Digital:</td> 
        <td>@Html.CheckBoxFor(m => m.isCertified)</td> 
        </tr> 
        <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; 
        Guid uID = userID.First(); 
UsersCertified uc = new UsersCertified(uID, model.certType, model.identifier); 

//HERE I NEED SET MY TABLE WITH MY MODEL... BUT SO MANY ERROR 

    context.SaveChanges(); 
} 
+0

난 그냥 context.sistema_UsersCertified.Add (UC)를 사용합니다; 예외 또는 빌드 오류입니까? 오류의 정확한 텍스트는 무엇입니까? – Kaido

+0

'sistema_UsersCertified' 란 무엇입니까? 아마도'DbSet '여야합니까? –

답변

1

오 나는 당신이 유형 UsersCertified의 모델을 만든 다음 시도되는 것 같아요 sistema_UsersCertified 유형의 데이터베이스 엔터티로 저장합니다.

시도

sistema_UsersCertified dbEntity = new sistema_UsersCertified(); 
dbEntity.CertType = ... 
context.sistema_UsersCertified.Add(dbEntity); 
+0

고마워 .....! –

관련 문제