Posts

Code First Approach with Entity Framework

Image
 1) To begin with the Code First Approach we need the below nuget packages in our Project. Microsoft.EntityFrameworkCore Microsoft.EntityFrameworkCore.SqlServer Microsoft.EntityFrameworkCore.Tools Microsoft.EntityFrameworkCore.Design One can easily install the above packages with the nuget package manager or its command line tool. Once installed you will get the below packages stacked in the installed window of nuget package manager 2) After nuget Package installation we can setup the connection string and our POCO entity classes. We can set our connection to DB in appsettings.json file as below Snap Shot. Now it's time to setup the DbContext class. You can create one normal class inheriting the DbContext class as below As above SS we have declared one Normal Class inheriting DbContext class in which we have an empty constructor where we need to send DBContextOptions to the base class. Below that we can declare our DbSets for required entity classes and have Default data that need

Getting Ready for Python Development on Ubuntu using VSCode

Image
Everybody knows Python is the most trending programming language in the current world. It's a very demanding programming language in Data Science and Machine Learning. Let's start creating a local environment for complete Python development. 1) Downloading VSCode  You can download the VSCode from the official Microsoft Link . Download .deb file for Ubuntu installation. You can install it using the usual double-click method or hitting the command " sudo dpkg -i vscode.deb" here " vscode.deb" is the file name that we downloaded. 2) Installing Extensions Search for python in extension search and install the Extension Pack from Microsoft. It have Python language server and Pylance language support extension. Once installation completes check if everything working fine.

Designing Model class with validation in ASP.NET MVC

The Generalized Example product model class. As given belowed. using System; // Using Data Annotation Library using System.ComponentModel.DataAnnotations; namespace modelDesigning.Models {     public class Product     {         // Product ID Decalration         // Key defines given Id is primary key         [Key]         // Required Annotation says its compulsory and required field.         [Required]         public int ProductID { get; set; }                         [Required]         // Max Length Annotation gives maximum length for string.         [MaxLength(50)]         public String ProductName { get; set; }         [Required]         public decimal Price { get; set; }         // Maximum length and minimum length of Description.         [MaxLength(100), MinLength(10)]         public string Product_Description { get; set; }     } }

Duplicate pimary key while inserting Exception in MVC

When we generate the scaffolding templates from the existing model for creating read-write and edit . We face an exception for the duplicate primary key if we do not provided primary key value. So the Question Is how to autogenerate the next primary key value? The answer is right here 1) Inside Create() Method Declare following Code.   // GET: Products/Create         public ActionResult Create()         {             Product product = new Product();             product.Product_Id = db.Products.Max(item => item.Product_Id)+1;             return View( product );         }  The red color code is newly added code. And the next time if you see the value of the primary key will be auto-generated.

How to Add Controller in MVC

Image
There are two approaches to add the controller in the ASP.NET MVC. Approach-1: Using Scaffolding method. Right Click on Controller Folder Select Add -> Controller  Following picture shows the controller template selected. Click Add button Name the controller as given image Click on the Add button and that all the controller will generate in the Controller Folder as given bellowed Image Approach - 2: By adding a normal class Right Click on Controller folder  Select Add Class or New Item Import the namespace using System.Web.Mvc; Inherit the class name Controller in it. And thats all the controller is ready.

Creating the new MVC project in visual studio and using View Data

Image
Creating the new MVC project in Visual Studio 2015 Open Visual Studio Goto File -> New -> Project Select Templates-> Visual C#-> Web -> Asp.NET Web Application Give project Name(Any Name you Want, I Used "MvcWebApp") Adding a Controller into the project Goto Solution Explorer -> Right Click On Controller Folder Add-> Controller -> Select MVC5 Controller-Empty(In Add Scaffold Box) Give the name for controller HomeController (Suffix xxController mandatory.)  It will generate following code with one Action Method. Now right click on Action Method And select Add View It will Add Index.cshtml int directory Views/Home/ in Solution Explorer. Now Add some code to Action Method Code for Index.cshtml  

Activating IIS (Internet Information Service) in your Windows PC

Image
IIS- Internet Information Services It is noting but the "Web Server" Provided by Microsoft in Windows operating system.             Adding/ Activating IIS in your operating System. Goto the Control Panel into your System./ Search " Control Panel " in Start Menu Select Programs and Features in Control Panel. Click Turn windows features on or off. It will open following Selection box. 5. Check all the check boxes and click OK. Tada that's all you have successfully installed IIS onto your system. 6. To check it out it's working or not  type http://localhost into your browser.