Home Asp.net MVC WPF Entity framework Core MVVM Project Step by Step

WPF Entity framework Core MVVM Project Step by Step

23 min read
0
0
4,458

This tutorial will teach you WPF Entity framework Core implement crud operations step by step. whose who interested in .Net Core Entity framework this is the best place which you learn.

First create a new project

Create new project on textbox type blank select blank solution give the name of the project I given name as StudentCrudApplication

After given the name Click create button.

Black Solution has been created with name of StudentCrudApplication

We should create following Class Libraries

1. Crud.Domain – class library

2. Crud.EF – class library

3.Crud.UI – wpf application

 

Crud.Domain

After that right click the Solution

Add a new project select WPF Class library

Give the name as Crud.Domain

Click Create.then your Crud.domain has been created.

After that right click the Solution

Add a new project select WPF Class library

After that create another class library as Crud.EF as we did ealiar.

Give the name as Crud.EF

After that right click the Solution

Add a new project select WPF Application

 

Give the name as Crud.UI

Click Next and Create then

 

Now you will be able to see structure of the solution

  1. Crud.Domain
  2. Crud.EF
  3. Crud.UI

you can see the screen shot image below

After that select the Crud.EF and right click install the Manage NuGet Packages

ADD the Following DEPENDINIES

  1. Microsoft.EntityframeworkCore.Sqlserver
  2. Micosoft.EntityFrameworkCore.Design
  3. Microsoft.EntityframeworkCore.Tools

Install all Dependencies

Type name of the Dependencies and install them.

Click Install

After complete the installation

Crud.Domain

Select the  Crud.domain

Create the folder

Right click the crud.domain  add-New folder and name it as Model

Inside the model folder create class file which name is

Student.cs

and paste the code below.

Create the Student . inside the class consist of following properties  id,stname,course

After that Create the folder inside the Crud.Domain which name is Services

inside the folder have to create the interface which name is  IDataService

the purpose of creating the file do the crud operations and called as entity all table are entity  crud operation.

IDataService.cs

select the Crud.EF and create the class which name is StudentDBContext.cs.we have establish the database connection in this file.all the table creation and set as primary key.

modelBuilder.Entity<Student>().HasKey(e => e.id); // set as the primary key here

database connection i will create the separte class and inhert the StudentDBContext class.

StudentDBContext.cs

select the Crud.EF again create another class which name is CrudContextFactory in this file i include the database connection

CrudContextFactory.cs

After that we have to create database for run this command.

select Crud.Ef  right click set as a started project then go to the main menu

Tools -> NuGet Package Manager -> Package Manager Console

then you can get the console . you have add-migration initial

then migration files has been created.

after that you have run the command as

now your database has been created you just open the sqlserver and check them database has created or not.if the database is created after we will do the crud functionality.

Crud.EF

Select the  Crud.FF

Create the folder

Right click the Crud.FF  add-New folder and name it as Services

Inside the Services folder have to create two classes which are GenericDataService.cs and NonqueryDataService.cs 

GenericDataService.cs

NonqueryDataService.cs

After that select Crud.EF create the another class which name is StudentCrudServices.cs

StudentCrudServices.cs class have to inhert ICrud class

this class consist of all the crud operation and validations.

StudentCrudServices.cs

After that select the Crud.UI and select the file MainWindow.xaml double click it and paste the following code.then the UI will be created.
 

After that double click the MainWindow.xaml.cs for writting the code

MainWindow.xaml.cs

i have attached the video link below. which will do this tutorials step by step.

    Load More Related Articles
    Load More By admin
    Load More In Asp.net MVC

    Leave a Reply

    Your email address will not be published.

    Check Also

    Node js React Mongodb Search Functionality

    In this articles will teach how to search records Node js React Express Mongodb.how the se…