Ich habe erste Code-Projekt MVC, aber ich erhalte unten Fehler NullException Fehler in MVC ersten Code-Einheit
Erste-Code! Daher gibt es keine Standarddatenbank.
Modellklasse
public class Applicant
{
public int ApplicantID { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public int PhoneNumber { get; set; }
}
Kontextklasse:
public class Context : DbContext
{
public List<Applicant> Applicants { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Applicant>().Property(r => r.ApplicantID)
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
}
}
Antragsteller repasority Klasse:
public Applicant Create(string username, string password, int phoneNumber, out int existResult)
{
if (context.Applicants.Where(x => x.UserName == username).ToString() != null)
{
applicant = new Applicant()
{
UserName = username,
Password = password,
PhoneNumber = phoneNumber,
};
context.Applicants.Add(applicant);
existResult = 1;
return applicant;
}
existResult = 0;
return applicant;
}
Und ich Code unten zu meinem web.config in meiner Web-Lösung hinzugefügt:
<connectionStrings>
<add connectionString="Data Source=.;Catalog=Homi;Integrated Security=True" providerName="System.Data.SqlClient" name="Context" />
</connectionStrings>
</configuration>
Hallo ist, vielen Dank für Ihre Pflege, was meinst du genau –
ist etwas weniger –
Blick auf diese:!?. http://stackoverflow.com/q/4660142/861716 Nur * Sie * kann den Code debuggen und prüfen, was Null ist (gilt auch für 'ArgumentNullException') Side note:' context.Applicants.Where (x => x.UserName == Benutzername) .ToString() 'gibt die Abfragezeichenfolge zurück. –