Welcome to Xamarin Guy Show Blog

Keep updated for latest and Greatest Posts from Xamarin guy

Asp.net core Web API join three tables with Guid [Sampurna]#4

Hey guys this articles that i am writing is an unofficial articles. If you are not executing then i am not resposible. You have to wait until i make a perfect tutorial on My Xamarin Guy Show.
@XamarinGuyShowOfficial

At first we are going to create a simple web api project.

We are going to join three tables with guid’s and create an API.
We will be using Employee,Department&Block classes and Employee class will be our master table class from where we are going to handle department and block.
Step1: Lets create models Folder. Which contain class: Department,Employee,Block,EmployeeContext,MyWish
Department.cs:

Block.cs

Employee.cs:

EmployeeContext.cs:

MyWish.cs

Step2:
Inside Startup.cs Class configure your database

Step3:
Inside package manager console:
Add-migration Initial
Update-Dtabase
Step4:
Now we are going to create different controllers : BlockController.cs,DepartmentController.cs,EmployeesController.cs inside controller class so you have to create 3 api controller classes:
BlockController.cs

DepartmentController.cs

EmployeesController.cs

Last Step is to use magic of postman:
Your localhost : http://localhost:50442/api/employees
That’s all add block and department inside the table:
For Depatment Post:
{
“departmentName”: “BackEndDeveloper”
}
For Block Post:
{
“blockName”: “BlockA”
}
At last Do crud operation for master employee table adding the guids of of Block and Department for employee.


{
"employeeName": "Yamlaa",
"departmentId": "e6f8f9de-4b92-4041-a6d9-ce014a94107e",
"blockId": "6904bf88-cbad-41fc-ac7d-befa4593a20c"
}

Your Put method will looklikethis:

{
"id": "9c190a26-be4e-4334-80cb-5a4e053b7d55",
"employeeName": "P",
"departmentId": "9910ea09-b2ed-4429-8385-44cd4707f9ac",
"blockId": "767fa211-028d-4081-b72d-d067d332ce32"


}

Output 😀

Leave a Reply

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.