I have MVC first code project but I get below error
First code! So there is no default database.
Model class
public class Applicant
{
public int ApplicantID { get; set; }
public string UserName { get; set; }
public string Password { get; set; }
public int PhoneNumber { get; set; }
}
Context class:
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);
}
}
Applicant repasority class:
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;
}
And I added below code to my web.config in my web solution:
<connectionStrings>
<add connectionString="Data Source=.;Catalog=Homi;Integrated Security=True" providerName="System.Data.SqlClient" name="Context" />
</connectionStrings>
</configuration>