Posts

Showing posts with the label Entity Framework

Donate

WPF MVVM - No connection string named 'MyEntities' could be found in the application config file.

Image
Hello Team, While working on a simple WPF MVVM application using Entity Framework 6.x and Visual Studio 2019, I encountered this strange error No connection string named 'MyEntities' could be found in the application config file . However, if I compile and debug my application, it would proceed with running the project. I've searched lots of information and most of the solutions presented were to copy the web.config or app.config file from a class library to the project that is set as the startup application. One thing I've noticed though is that this error appears only on the XAML page of where the DataContext is assigned. After doing some experiments of modifying my application, I came up with a solution that is instead of setting the DataContext in the XAML like below: <Window.DataContext> <viewModel:StudentViewModel/> </Window.DataContext> I assigned the DataContext in the code behind of the MainWindow and thus the error message disappeared.

Bootstrap Modal In ASP.NET MVC With CRUD Operations

Image
Good afternoon fellow developers! I have been working with Bootstrap Modals before and it's time to demonstrate its significance using a simple ASP.NET MVC CRUD (Create Update Delete) application project using Entity Framework Database First approach. First is to create a basic BookDetails table on your SQL Server instance. USE [DemoDB] GO /****** Object: Table [dbo].[BookDetails] Script Date: 11/2/2020 12:26:53 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[BookDetails]( [BookSerialNo] [int] IDENTITY (1,1) NOT NULL , [BookISBN] [ nchar ](15) NULL , [BookTitle] [varchar](120) NULL , [BookAuthor] [varchar](60) NULL , [BookPublisher] [varchar](50) NULL , [BookCategory] [varchar](20) NULL , PRIMARY KEY CLUSTERED ( [BookSerialNo] ASC ) WITH (PAD_INDEX = OFF , STATISTICS_NORECOMPUTE = OFF , IGNORE_DUP_KEY = OFF , ALLOW_ROW_LOCKS = ON , ALLOW_PAGE_LOCKS = ON ) ON [ PRIMARY ] ) ON [ PRIMARY ] GO Next is to create an ASP.

Filtering, Paging and Searching Bootstrap Table in ASP.NET MVC

Image
Good afternoon! The previous two articles on using Bootstrap Tables by Wenzhixin were simply displaying, sorting and paging records. This tutorial will demonstrate on how apply filtering features to the table. First is to create an ASP.NET MVC project and then add an ADO.NET Entity Data Model that will use the Northwind Database Employees table. Next is to add an EmployeeView model that will be used as field names by the Bootstrap Table. The source code for the View Model and the EmployeeController is presented can be copied from this article Sort Bootstrap Table Date Column By Wenzhixin Using Moment.js In ASP.NET MVC . To enable filtering of the table, obtain the bootstrap-table-filter-control.js from the Bootstrap Table source code at github and reference it in your page as presented below: <link href= "~/Content/bootstrap.min.css" rel= "stylesheet" /> <link href= "~/Content/bootstrap-table.css" rel= "stylesheet" /> <script

Sort Bootstrap Table Date Column By Using Moment.js In ASP.NET MVC

Image
Hello, In this tutorial, I'll demonstrate on how to sort a date column of a Bootstrap Table by Wenzhixin using Moment.js. First is to create an empty ASP.NET MVC project and then add an ADO.NET Entity Model that references the Employee table of Northwinds database. Next is to define an Employee ViewModel class that will hold the information to be utilized by the Bootstrap table. public class EmployeeViewModel { public int EmployeeID { get ; set ; } public string EmployeeName { get ; set ; } public DateTime BirthDate { get ; set ; } public DateTime HireDate { get ; set ; } public string Address { get ; set ; } public string PostalCode { get ; set ; } public string Country { get ; set ; } } Then add a new controller called Employee that declares a Northwind context object, queries the database and returns the model object as JSON. public class EmployeeController : Controller { private NorthwindEntities _context; public EmployeeController() { _con

Using Bootstrap Table Wenzhixin With ASP.NET MVC

Image
Good evening guys and gals! In this tutorial, I will show you on how to display records in tabular format using Bootstrap Table created by Wenzhixin in ASP.NET MVC. First, you need to have AdventureWorks Database since this is the database used in the demo. Next is to create an ASP.NET MVC project and then add an ADO.NET Entity Model that targets the AdventureWorks DB specifically the tables People , EmployeeDepartmentHistories , Departments , Shifts , BusinessEntityAddresses and Addresses . Proceed by adding an EmployeeViewModel class that contains properties of the Employee. This class will be used by the Bootstrap Table's columns property. public class EmployeeViewModel { public int BusinessEntityId { get ; set ; } public string EmployeeName { get ; set ; } public string Address { get ; set ; } public string PostalCode { get ; set ; } public string DepartmentName { get ; set ; } public string DepartmentGroupName { get ; set ; } public string Shif

WPF CRUD With DataGrid, Entity Framework And VB.NET

Image
Good morning! Here's the VB.NET version of this post WPF CRUD with DataGrid and Entity Framework C# . The steps to accomplish basing from the C# post are: a. Run the create table script assuming that you haven't created the Students table. b. Create a VB.NET WPF project. c. Replace the XAML markup of the window control. Once done, the scripts for the repository class and window code-behind are as follows: Repository Class Public Class StudentRepository Private studentContext As StudentEntities = Nothing Public Sub New () studentContext = New StudentEntities() End Sub Public Function GetStudent ( ByVal id As Integer ) As Student Return studentContext.Students.Find(id) End Function Public Function GetAll () As List( Of Student) Return studentContext.Students.ToList() End Function Public Sub AddStudent ( ByVal student As Student) If student IsNot Nothing Then

WPF CRUD With DataGrid, Entity Framework And C#.NET

Image
Good evening! Here's a simple WPF CRUD(Create/Update/Delete) application using DataGrid and Entity Framework. This doesn't involve the MVVM pattern and input validation. Maybe if I have time, in the future I'll post an MVVM equivalent post ( Update: I already have additional examples using RepoDB ORM and MVVM pattern in both C# and VB.NET at the end of this article ). So to proceed, execute the SQL script below and make sure to replace the database name with an existing one. USE [your_database] GO /****** Object: Table [dbo].[Students] Script Date: 3/31/2018 11:24:23 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Students]( [ID] [ int ] IDENTITY ( 1 , 1 ) NOT NULL , [Name] [ varchar ]( 50 ) NULL , [Age] [ int ] NULL , [Address] [ varchar ]( 50 ) NULL , [Contact] [ varchar ]( 50 ) NULL , CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED ( [ID] ASC ) WITH (PAD_INDEX = OFF , STATISTICS_N

Donate