I'm very much begginer to ASP.net and Just followed a tutorial and created a small web app.I understood the basics up to creating a Model in Visual Studio Mac Edition (2022) , However , when I tried to use entity frame work to Link controller and create a view with user interface ,I get null value for "DB context Class to Use" field. I don't know how to fix this issue since I'm using Mac edition of Visual Studio. DB connect Class to Use is Null
Following is my code in the Model class
using System;
using System.Linq;
using System.Data;
namespace WiseTaskMgtSystem.Models
{
public class UserModel
{
public int ID { get; set; }
public String UserName { get; set; }
public String password { get; set; }
public UserModel()
{
}
}
}
I would be highly appreciated if someone could assist me on this to solve the issue.
Thank you.!
CodePudding user response:
did you add DBcontextin your solution ? take Image from solution explorer
CodePudding user response:
DbContext is base class for managing database connections and provides functionality for CRUD operations, that is Database related functionality like data access methods to interact with Database.
In Example below UserProfile
is Table in the Database.
public class UsersContext : DbContext
{
public UsersContext()
: base("DefaultConnection")
{
}
public DbSet<UserProfile> UserProfiles { get; set; }
}
// Class UserProfile maps to the Database Table [UserProfile]
[Table("UserProfile")]
public class UserProfile
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int UserId { get; set; }
public string UserName { get; set; }
}