- // Index.cshtml
- @{
- ViewBag.Title = "EventManagement List";
- }
EventManagement List
"EventManagementTable" class="display">
- @*Semantic UI*@
- @*
"employeeTable" class="ui celled table">*@
- @*Bootstrap*@
- @*
"employeeTable" class="table table-striped table-bordered">*@
TrainingID TrainingType TrainingDescription Price Venue Facilitator WhoAttend RSVP TrainingID TrainingType TrainingDescription Price Venue Facilitator WhoAttend RSVP - "stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.20/datatables.min.css" />
- "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
- "https://cdn.datatables.net/1.10.15/css/dataTables.jqueryui.min.css" rel="stylesheet" />
- "//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.6/semantic.min.css" rel="stylesheet" />
- "https://cdn.datatables.net/1.10.15/css/dataTables.semanticui.min.css" rel="stylesheet" />
- "https://cdn.datatables.net/1.10.15/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
- @section scripts{
- "//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0.0-alpha.6/css/bootstrap.css" rel="stylesheet"/>
- }
Hi TeamI want to find a way to access my members of model class to my Controller class, when using ApplicationDbContext. The database is attached to my App_Data and has table to it, and want to find a way to access those fields in my Controller class using ApplicationDbContext, can anyone help me if there is a way. Below is my logic so far and screen shot showing what i am aiming to achieve.
- //Controller class
- using System.Web;
- using System.Web.Mvc;
- using ContentManagementSystem.Filters;
- using ContentManagementSystem.Models;
- using Microsoft.AspNet.Identity.EntityFramework;
- namespace ContentManagementSystem.Controllers
- {
- public class DashboardController : Controller
- {
- public ActionResult _Index()
- {
- return View();
- }
- public ActionResult GetList()
- {
- using(ApplicationDbContext db = new ApplicationDbContext())
- {
- var emptList = db.Users.
- return Json(new { data = emp })
- }
- }
- }
- }
- // Model class
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using Microsoft.AspNet.Identity.EntityFramework;
- namespace ContentManagementSystem.Models
- {
- public class ApplicationUser:IdentityUser
- {
- public string Email { get; set; }
- public bool ConfirmedEmail { get; set; }
- }
- public class ApplicationDbContext: IdentityDbContext
- {
- public ApplicationDbContext()
- : base("eNtsaOnlineRegistrationDB")
- {
- }
- }
- }
16 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Gcobani,what you are showing is your connection string. you need to use the below command to generate models using this connection string. scaffold-DBContext .............. command will generate all tables into c# class and DBcontext class which will have respective properties etc.Hi GuptaDo i need to use this command via nuget on the console?
yes nuget package manager consoleHow do i then check the naming of my model?- PM> scaffold-DBContext "Data Source="(LocalDb)\MSSQLLocalDB; Catalog=eNtsaOnlineRegistrationDB;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer-OutputDir Models
you should be having new DBcontext and models classes generated in your solution.verify Models folder in your solution if the below command was successfully executed.Hi Gupta- scaffold-DBContext "Data Source="(LocalDb)\MSSQLLocalDB; Catalog=eNtsaOnlineRegistrationDB;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer-OutputDir Models
- >>
I am unable to see from the project folder under Model, my new DbContext. Have i done something wrong on my command? please assist, thanks.
scaffold-DBContext "Data Source=(LocalDb)\MSSQLLocalDB; Catalog=eNtsaOnlineRegistrationDB;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer-OutputDir Modelsthere was one extra ", check with this. it should be excuted without any error..Hi MatesI ran this new command, i was getting an error, please assist me thanks. Had to look at stackoverflow for these error and did some Install-Packges like EntityFrameworksTools and SqlServer. I had now new error while re -running same command.
i think there is no Models folder under your solution, create one with name Models and try.Hi MateNo there is unfortunately please see below for more information. After following Github still no luck even if i try to use this special command scaffold-DBContext "Data Source=(LocalDb)\MSSQLLocalDB; Catalog=eNtsaOnlineRegistrationDB;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer-Verbose it does not compile successfully. Ok i Re ran the command putting the space after SqlServer and got this error, scaffold-DBContext : Exception calling "Start" with "1" argument(s): "The system cannot find the file specified".- PM> scaffold-DBContext "Data Source=(LocalDb)\MSSQLLocalDB; Catalog=eNtsaOnlineRegistrationDB;Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -Verbose
I got rid of this error, but the problem im still unable to see new Model class under my folder. How i fix it its below install-package Microsoft.EntityFramework.Tools v 3.1.1
i think, it is case sensitive, make sure you type correctly S is captial in ScaffoldScaffold-DbContextHi Gupta-
"eNtsaOnlineRegistrationDB" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\eNtsaOnlineRegistrationDB.mdf;Initial Catalog=master; Integrated Security=True" providerName="System.Data.SqlClient" />
I did that was missing an package, of which is i am now getting Keyword not supported 'catalog'. Busy looking at this issue,dont know if my connectionString is correctHi MateI got this link from CodeProject, had to follow the documentation from step 2 step, missing update of the package seemed relevant and had to re do the command putting -OutputDir Models all were executed well no error. After the update though for the Install-Package Microsoft.EntityFrameworkCore.Tools.https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/powershellKnow the answer? Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions01ForumsTop experts
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answersFull leaderboard →
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Loading
Ashutosh GuptaRank #805 · 2.9K reputationPosted Feb 10, 2020, 12:00 AM EST
Guest UserRank #877 · 2.5K reputationPosted Feb 10, 2020, 12:51 AM EST