What Can We Expect from the Future of CNC Machining?
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at What Can We Expect from the Future of CNC Machining? Computer Numerical Control (CNC) has changed how companies manufacture their products. These changes have been amplified even further with the integration of technology into CNC machining.
Even though CNC machining services have largely worked the same way for decades, that is going to change as more and more industries accept automation as the future of manufacturing. The future of CNC machining is a very exciting one and below, we will look at a few exciting things that we can expect in future.
Internet of Things
We live in automated homes with most of the planning and organization of our lives done on devices. Why can't the same be done in a factory? Turns out, the Internet of Things (IoT) is enabling automation in ways not seen before. IoT allows machines to “talk” to each other over a network so they can work in tandem to produce a final product.
Because these machines are also connected to mobile devices or computers, some CNC machining companies are offering online CNC Machining services. You no longer have to go to a factory or arrange a meeting to have a project completed; most of these companies offer their CNC services online where you just need to send a CAD file with everything you need to be done, then wait for a quote from a company. This is not only happening in CNC prototyping and machining; you can also send in your designs for injection molding services, rapid machining and more.
Cheaper CNC Services
CNC machines are getting cheaper. That is why it is becoming cheaper to commission a company that offers CNC services China to do any type of machining for you. It is not only cheaper for customers, but it is also cheaper for companies too.
Companies can buy these machines at a fraction of the cost they used to, meaning that the barrier of entry into this industry has been lowered even further. Because the cost of entry is so low, companies can offer a diverse range of services including prototype manufacturing and prototype machining.
Companies also get to save money on labor because they do not have to hire as many people to handle their CNC services. These include manufacturing and online CNC services. These savings can then be passed on to consumers in the form of cheaper services.
Smaller Devices, Some in Our Homes
In the past, companies had huge CNC machines that were dangerous to work with, expensive and immobile. As the technology in this space has matured, so has the manufacturing process of these machines. It is not difficult to now find prototype molding machines that can fit in a room. Machines have become smaller, and since they now can interact with each other, companies are favoring many smaller portable devices instead of larger, immobile machines.
A lot of people do not consider 3D printers part of the CNC machining family, but they are. 3D machines can help businesses and entrepreneurs offer some simple services like injection molding services and therefore can themselves open up new industry segments for those who invest in them.
Fears of Unemployment
One of the biggest fears of automation is that a huge segment of the working population could lose its jobs. This fear stems from the fact that a single machine can handle tasks previously handled by ten people. This is a problem that business people and stakeholders have to think about.
On the other hand, automation can help
create new jobs. The way it will do this is the machines that allow companies to offer online CNC machining services will need maintenance, updates, and upgrades. Because of this, technicians will be needed to troubleshoot and take care of them. Further, the software used in these machines will have to be coded by a programmer. Programmers who have machine learning skills could be in higher demand than they are now if processes like sheet metal prototyping and sheet metal fabrication become fully automated.
The Rise in the Prominence of Robots
Robots can do two things that humans cannot:
- lift extremely heavy loads
- work indefinitely with little to no downtime
As CNC machining changes, the role of robots will change. Robots can transfer large, heavy loads between other machines. They can also “talk” to these other machines to feed them materials and move products that are done or that need to go to the next stage.
Robots will also become part of CNC machines instead of add-ons. Because of this, processes like rapid machining will take an even shorter amount of time.
Increase in Machine Reliability and User Satisfaction
When the merger between IoT and CNC machining is complete, machines will be able to work indefinitely. A company that offers rapid machining cannot afford to have any downtime. This is why engineers are working hard to improve the reliability of these machines. As the demand for products that pass through the CNC process increases, so will the need for faster turn-around times, with these deadlines only met if the CNC machines perform at optimum levels.
Also, as more and more companies turn to automated systems, developers and programmers will have to make the control systems a lot more intuitive. This means that they will have to simplify their user interfaces and make them more user-friendly. This will have the added benefit of lowering the entry qualification requirements for those looking to work with this software and machines.
Increase in Product Quality
CNC machines will only get better as companies strive to produce the best products possible. Companies that carry out
CNC machining are already tightening their tolerances and quality control systems. A company like RapidDirect has already streamlined its processes to complete orders of any quality, using a wide selection of materials, at affordable costs and at the highest quality possible.
The firm offers additional efficiencies such as automated DfM assessments, reliable real-time order tracking and online quotes, which can be managed easily thanks to an integrated quote management system. These solutions make it quick and easy for customers to use RapidDirect to produce quality products to their exact specifications.
Better Tech Support
There is no doubt that the world of CNC machining will change in the future as more companies adopt different technologies. Before this change is complete though, and companies can offer better rapid tooling services, there will be a learning curve to get over. The best way to get over this curve is to extensively engage tech support representatives. That is why companies that offer these technologies will have to improve their tech support offerings.
Further Investments in CNC Machining
To stay competitive, companies will have no choice but to invest in CNC machining. If they do not, companies that offer CNC machining China, for example, could decimate their market shares. In doing so, these companies will effectively be tripling their work hours because machines and robots work 24 hours a day while humans can work just 8.
The Future is Already Here
Companies have to start thinking of the future of CNC machining if they are not already. Rapid prototyping services, as well as other services in the CNC machining industry, are already being automated and companies that do not embrace this automation risk being left behind. There are so many reasons to automate, with some of them being to stay competitive and cut manufacturing costs.
Staying competitive means delivering better-quality products at a higher quantity to customers faster than your competition can. CNC machining automation will help reduce waste and therefore help companies cut costs. The changes to an automated industry might cost a lot of money, but the upside is so huge that companies would be losing out if they do not take this path.
There is so much to look forward to in the world of CNC machining with so much more to come that we cannot even envision today. All we can do is wait and hope the future is even brighter than a lot of people are predicting it will be.
Voltmeter & Ammeter in Proteus ISIS
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at How to use Voltmeter & Ammeter in Proteus ISIS. It's our 4th tutorial in Proteus series. While designing an electronics project, voltage & current measurements are essential debugging features, as they help in understanding circuit behavior.
Proteus has builtin instruments for voltage & current measurement. We have have their probes and today we will discuss them in detail. First have a look at Voltmeter in Proteus ISIS:
How to use Voltmeter in Proteus ISIS
- DC Voltmeter is used to measure the voltage difference across any DC component.
- In order to use DC Voltmeter, we need to click on Virtual Instruments Mode, as shown in the figure.
- In Instruments list, we have DC voltmeter, so click it and place it in your Proteus workspace.
- I am going to use the same circuit, which we have designed in first lecture, shown in below figure:
- As you can see in the figure, I have placed two voltmeters, one at the input and second at the last LED.
- Because of 100kohm resistance, there's a slight drop in the voltage at last two LEDs.
- Moreover, Voltmeters are placed in parallel to these component.
- We can also use Voltage Probe to measure voltage at any point in the electronic circuit.
- So, click on Voltage Probe in the left toolbar and connect it to any point in your circuit and its voltage will be displayed.
- I have placed two Voltage probes on my circuit, as shown in below figure.
- Voltage Probe provides value up to five decimal points, while DC Voltmeter provides value up to 2 decimal points.
- Voltage probes are quite helpful as they are small in size and easy to place in the circuit.
So, that was all about Voltmeter in Proteus. Now, let's have a look at How to use Ammeter in Proteus ISIS:
How to use Ammeter in Proteus ISIS
- DC Ammeter is used to measure the current passing through any DC component.
- We need to click on Virtual Instruments Mode and then click on DC Ammeter.
- Place this Ammeter in series, as shown in below figure:
- We aren't getting any value on our Ammeter as these LEDs are not drawing much current.
- But, you can see we have placed the Ammeter in series, we will use it a lot in coming projects.
So, that was all about How to use Voltmeter & Ammeter in Proteus. I hope you have enjoyed today's tutorial. Till next tutorial, take care & have fun !!! :)
How to Increase Workspace in Proteus
Hello friends, hope you all are fine and having fun with your lives. Today's post is about How to increase Workspace in Proteus. It's our 3rd tutorial in Proteus series. Its quite a simple tutorial and along with this trick, I will also share few commonly used features or Proteus. Once, I was working on a simulation project in which I have to design a complete load management system in Proteus and it was quite messy as I have to include a lot of components and the area of Proteus got quite small for that and then I encountered this problem i.e. where to place the components.
You have seen in Proteus software that there's a blue rectangle which is considered as the workspace in Proteus. This area is constant and doesn't increase or decrease on its own. So if we are dealing with some messy circuit design then we have to increase this area, which we are going to discuss today. If you have downloaded my Arduino Library for Proteus, then you must have seen that the size of Arduino Mega 2560 is quite big and when I design Proteus simulations in which I need to use Arduino Mega, I have to increase the Proteus workspace to embedded all the other components. So, let's get started with how to increase Workspace in Proteus:
How to Increase Workspace in Proteus ???
- First of all, if you are working on some project in Proteus then simply don't increase the area because when you increase the area then components get too small and its quite difficult to arrange or connect them with each other.
- So, my suggestion is to keep using the default size, unless your circuit got messy and you actually need more space.
- Let's open Proteus software and place few components in it, as an example I am just placing PIC Microcontrollers to cover the available space, as shown in below figure:
- You can see in above figure, I have randomly placed 8 PIC Microcontrollers, just to fill the space.
- Now suppose I want to add four more Microcontrollers in this Proteus file, there's no place to add them.
- Now in order to add more components, we need to increase the size of available workspace in Proteus.
- In order to do so, click on Systems in above menu bar and then click on Set Sheet Sizes as shown in below figure:
- Now when you click it, a new pop up window will open up, as shown in the figure on right side.
- You can see in the figure, there are six sizes available for the user to select.
- First five are fixed sizes while the sixth one is user defined and you can set it to any size you want.
- The default size of workspace in Proteus is A4, which is the first option i.e. 10inch by 7 inch.
- So, now let's change this selection and I am selecting the fifth option so now the size is 15inch by 10 inch, as shown in below figure:
- Now its quite obvious from the above figure that the area has increased.
- We have the same 8 PIC Microcontrollers but now we have more free space.
Right Click to Delete Component
- Proteus has a quick way to delete any component or wire.
- You need to right click on your component/wire for 2 times and it will be removed/deleted from the workspace.
- It's quite helpful, especially in designing complex simulations.
Default Terminal in Proteus
- Let's discuss Default Terminal as well, which is used to keep the schematic organized & clear.
- We can get them by clicking on Terminals Mode first and then click on Default, as shown in figure on right side.
- In our previous lecture, we have designed a simple LED circuit, so let's make small changes in it, as shown in below figure:
- You can see in above figure that I have deleted the wires and placed these default terminals on both sides.
- In order to delete these wires, I have simply double right clicked on each wire and placed these terminals.
- Now, double click on each terminal and provide it a name, as shown in below figure:
- As you can see in above figure, top two Terminals are named as Terminal1 and below two terminals are named as Terminal2.
- So, although these terminals are not connected together but Proteus considers "Terminals with same name" as connected.
- If we run our simulation now, we will get the similar results, as shown in below figure:
- These default Terminals are too helpful, as in complex projects, adding too much wires make the simulation quite messy. ( We will use them in coming lectures )
So, that's how you can quite easily increase workspace in Proteus ISIS. That's all for today, it was quite easy tutorial but still if you are having any problems, then ask in comments and I will resolve them. Till next tutorial, take care !!! :)
Simulate First Electronics Project in Proteus ISIS
Hello friends, I hope you all are doing great. In today's tutorial, we will simulate our
First Electronics Project in Proteus ISIS. It's our 2nd tutorial in Proteus series. In our previous tutorial, we have seen a basic Introduction to Proteus and today, we will design a simple electronics circuit in it and will also simulate it.
If you want to work on Proteus, then you must have some prior knowledge about electronics. Proteus doesn't provide any suggestion about circuit designing so if you don't have electronics knowledge then you can't work with Proteus. Throughout this series, I will keep on explaining electronics circuits as well and will also embedded related components' links. So, if you are new to electronics then no need to worry and just follow these instructions and also do read those embedded links to understand electronic components. So, let's Create our First Project in Proteus:
Simulate First Electronics Project in Proteus ISIS
- Open your Proteus ISIS software and then click on Components Mode in left menu tab, as shown in the figure.
- After that click on the P (Pick from Libraries) Button, and a new window will open up.
- This new window is called Pick Devices and is used to make search for electronics components.
- Proteus has a huge database of electronics components in the form of libraries. i.e. Diode Library will have all the diode components.
- So, from these millions of components, we need to make a search for our required components to design electronic circuit.
- You can see Pick Devices window in below figure, so let's first discuss its layout:
- Keywords textbox is used to make a search for any component and Proteus will display the related components in Results panel. ( We will search in a while )
- Category Section displays all the categories available in Proteus and when you click on any category then it's components will be displayed in Results panel.
- After that, we have Sub-category & Manufacturer, rite now I don't have any.
- On the right side we have Schematic Preview & PCB Review, so when we select any component then its respective Previews will be shown here.
- So, now let's make a search for LED, as shown in below figure:
- As you can see in above figure that Proteus has provided us with 141 Results and I have boxed four LEDs, which I am going to use in my circuit.
- Moreover, Category section is now showing only those categories which are related to searched keyword.
- Moreover, we also have a Schematic Preview but we don't have any PCB Preview as it's not available for this component.
- So, double click on these four LEDs and they will be added in Proteus workspace.
- Moreover, we also need to add resistance so make a search for resistance, as shown in below figure:
- Double click on this RES component and then close this Pick Devices window.
- You will get these selected components in the Devices section, as shown in below figure:
- As we are designing a simple project so we have selected just four components but in complex projects, we have a long list of components in this Devices section and it proves quite helpful.
- So, let's place these components, one by one in the central work area.
- You can drag & drop them OR can select by clicking and then again click to place.
- I have placed these components in the work area, as shown in figure on right side.
- So, now let's connect them together using wires and for that, we need to click on the pin terminal of each component.
- I have combined these electronic components together using wires, as shown in below figure:
- Now we need to provide voltage supply to this circuit and there are several voltage sources in Proteus. ( We will cover them in coming lectures )
- For now, let's click on the Terminals Mode in the left Toolbar and you will get Proteus Terminals, as shown in figure on right side.
- From these terminals, we are going to use Power & Ground, so place them in the circuit, as shown in below figure:
- We will discuss all these Terminal Components in detail in our coming lectures.
- If we place multiple Ground components in the circuit then Proteus will consider them all as connected/short.
- These Terminals are quite helpful, as in complex circuits, these wires can become too messy and we can avoid them by using these terminals.
- So, we have completely designed our circuit but we need to change the properties of these components a little.
- So, double click on resistance to open its Properties Panel, as shown in below figure:
- From this Edit Component window, we can edit different properties of selected component.
- As you can see, first we have Component Reference, that's the name of our component i.e. R1. If we have multiple resistances, then there names will be R2, R3 and so on.
- We can't have multiple items with same Component Reference, as it will create an error.
- Second Property defines the resistance of the component and I have changed it from 10k to 1k.
- Then we have Model Type and its analog.
- Finally we have PCB Package, we will use it when we will be designing the PCB design of this circuit.
- So, click on the OK Button and resistance value will change from 10k to 1k.
- Now, double click on first LED to open its Properties Panel, as shown in below figure:
- As LED is a bit complex component as compared to resistance, that's why it has a lot more Properties to Edit.
- As we are designing a digital circuit, so we need to change the Model Type of LED from Analog to Digital and then click on the OK Button.
- You need to change this Model Type for all these four LEDs.
- So, now we have completely designed our first electronic circuit in Proteus.
- Let's run this simulation, by clicking the Play button at the bottom.
- If everything goes fine, then all LEDs will glow, as shown in below figure:
- We have successfully simulated our first electronics circuit in Proteus ISIS and you can see these LEDs have different colors as specified in their Reference Value.
So, that was all for today. I hope you have enjoyed today's tutorial. In the next lecture, we will have a look at How to use Relays in Proteus ISIS. Till then take care & have fun !!! :)
Introduction to Proteus
Hello readers, I hope you all are doing great. In today's tutorial, I am going to share a detailed
Introduction to Proteus. It's our first tutorial in Proteus series. Today's tutorial is for beginners but still I would suggest you to read it once, as I am going to explain why Proteus?
Throughout our Engineering Course, we have to design a lot of electronics or embedded circuits and it's always a best approach to simulate these circuits first on some simulation software i.e. Proteus, PSPice etc., before assembling them on actual hardware. Among these simulation software, Proteus is my favorite one so let's get started with detailed Introduction to Proteus:
Introduction to Proteus ISIS
- Proteus Design Suite (designed by Labcenter Electronics Ltd.) is a software tool set, mainly used for creating schematics, simulating Electronics & Embedded Circuits and designing PCB Layouts.
- Proteus ISIS is used by Engineering students & professionals to create schematics & simulations of different electronic circuits.
- Proteus ARES is used for designing PCB Layouts of electronic circuits.
- It's available in four languages i.e. English, Chinese, Spanish & French.
Why use Proteus ?
"Our circuit is working perfectly on Proteus but when we have implemented it on hardware, it's not working.
" I receive a lot of such questions from engineering students, that's why, I am explaining what's the real purpose of Proteus:
- Proteus is quite lenient in circuit designing and it works on ideal conditions i.e. if you don't add pull up resistors in Proteus simulation, then it won't give garbage value.
- Proteus is also used for PCB designing, we use Proteus ARES for that. ( We will discuss it in upcoming lectures )
So, when I am working on some electronics circuit, then I first design the
simulation on Proteus ISIS and once I got sure that everything's working fine then I design its circuit on either the vero board or the bread board and again I perform some real world testing & when I got sure that my circuit is fully working then I design its PCB in Proteus ARES.
- Proteus is also used for designing/testing programming codes for different Microcontrollers i.e. Arduino, PIC Microcontroller, 8051 etc.
In Embedded projects, we need to design a programming code for Microcontrollers and for designing such codes you have to perform a lot of testing, which involves uploading code to Microcontroller. So, in such projects, Proteus is a great relief. Let's say, you have to print some strings on 20x4 LCD, then its quite annoying to burn the Microcontroller several times for typographical errors. Instead, design a circuit in Proteus and test your code in the simulation and once you are sure that you are getting perfect output then burn your PIC Microcontroller and test it on real hardware. Quite easy and handy. In the coming classes, I will show you how to burn code in Microcontrollers in Proteus.
Note: In code testing, there's again a possibility that you get different results in real hardware but its quite rare and mostly happens in delay functions.
Getting Started With Proteus
You can download Proteus software from it's
official website and you should also read
How to Download & Install Proteus software. So now I hope you have installed Proteus and ready to work on it:
- Click on Proteus ISIS and it will open up as shown in below image.
- In the central area surrounded by blue lines, we design our circuit i.e. place the components and then join them together.
- As you can see in above figure that we have a lot of icons in Proteus software, so let's first understand these sections one by one.
- In the below image, I have divided the Proteus font-end in four sections:
- Section 1 is a toolbar which you would have seen on many simulation software, it has simple functionalities i.e. first icon to create a new layout, second one to open an existing layout, next one is to save layout, then there comes few zooming options and few other tools which we will discuss in coming tutorials.
- Section 2 has two buttons. P is used to open the components list and E is used for editing purposes, like you want to edit the properties of any component then simply click on that component and then click on E and it will open the properties of that component and you can easily edit it.
- Section 3 has different tools, used for designing circuits, we will discuss them in detail, at the end of today's tutorial.
- Section 4 is the remote control section of Proteus, as it contains four buttons i.e. Play, Step, Pause & Stop. In order to run the simulation, we have to click on this play button.
Component Selection in Proteus ISIS
- As shown in below image, click on the icon that says Click # 1, it's a Component Mode Icon.
- After that click on P button and a new window will open up named Pick Devices.
- In this new window there's a textbox on which Keyword is written, this text box is used for the component search.
- Proteus database has unlimited components in it so now in order to get your desired component, you have to search for it as I did.
- I have searched for PIC16F877A and Proteus provided me that component along with its preview in top right corner and PCB package ( if available ). Unfortunately, my Proteus doesn't have the PCB preview of PIC16F877A that's why it's blank.
- In order to add the component in Proteus workspace, either double click on it or click on the OK button.
Instruments in Proteus ISIS
- There are few measuring instruments available in Proteus, which you can open by clicking the Instruments Icon, as shown in figure on right side.
- First one is oscilloscope, we use it for viewing the behavior of different signals generated.
- Another important instrument is Virtual Terminal, it is shown on the fourth number. This Virtual Terminal is used for checking data coming through Serial Port.
- Then there's Signal Generator, it is used to generate signal like sine wave of desired frequency.
- We also have Voltmeter & Ammeter for both AC & DC.
- We will discuss them in detail in our coming lectures.
- As you can see in figure on right side, Icon A is called Graph mode, used to create graphs of voltage and current. It has different style of graphs.
- Icon B and C are voltage and current probes respectively. Suppose you have designed some circuit in Proteus and you want to check the value of voltage at any point in the circuit. In order to do so, simply select this voltage probe and place it there and when you run your circuit, the probe will show the value of voltage above it and same for current probe.
- Icon D is used when we want to design our own component in Proteus.
- Icon E is a simple text editor, used for placing labels, warning or components names etc.
So, that was all for today. I hope you have enjoyed this detailed Introduction to Proteus. If you have any question, feel free to ask in comments and also subscribe through email to our mailing list, so that you don't miss any part of this tutorial series. Stay blessed. Take care.
DbContext Class in Entity Framework Core
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at what is DbContext Class in Entity Framework Core. It's our 17th tutorial in ASP.NET Core series. In our previous tutorial, we have discussed Entity Framework Core in detail and have also installed it in our web application.
So, now we need understand how to work with Entity Framework Core and for that we have to look at its classes & functions. So, today we will discuss one of its class named DBContext in detail:
DbContext Class in Entity Framework Core
- EF Core contains an important class named DbContext, which is mainly responsible for communication between Database & software objects.
- We communicate with our database using this DbContext class and we can also map our fetched data to software objects i.e. properties.
- So, in order to use this DbContext class, we have to create a new class and then inherit it from DbContext Class.
- When we inherit our new class from DBContext Class, then we will be able to call all its members from our new class.
- So, I am going to create a new class in Models folder, as Models are going to communicate with the database.
- I have named this class TepDbContext and have inherited it from DbContext class, as shown in figure on right side.
DbContextOptions class in EF Core
- DbContextOptions class in EF Core contains all the configuration information about database i.e. database name, database provider, database connection string etc.
- We need to use DbContextOptions class along with DbContext class, so let's create a Constructor of DBContext class, as shown in below figure:
- You can see in above figure that I have created a constructor of TEPDbContext class and then instantiated DbContextOptions class as a parameter.
- After that, I have provided TepDbContext as a parameter inside < >, thus this option class is applied to our newly created TepDbContext class.
- Next, I have created its object titled options and finally called the base constructor from DBContext class and provided this options object as a parameter.
DbSet Property in EF Core
- So far, we have discussed two classes from EF Core and now it's time to have a look at this property in EF Core titled DBSet.
- DBSet Property is used to map the data from software objects to underlying database.
- Currently, we have just Engineers.cs file, which has the data properties, that need to be stored in our database.
- So, let's create a new property in our TepDBContext class named DBSet, as shown in below figure:
- As you can see we have created a new DbSet Property of type Engineers and given it a name DbEngineers. ( We will use it later )
So, we have successfully created our
TepDbContext class and have updated it, so, now its time to register this newly created class with dependency injection of ASP.NET Core.
Database Connection String in App Settings
- We need to provide authentication settings for our database, which we will add in appsettings.json file, so that we could use it anywhere in our project.
- I am using MySQL database and thus provided its connection string, as shown in below figure:
- You can see in above code that I have created a new section named ConnectionStrings and inside it, I have create DbConnection variable and have assigned DB connection string to it.
- In the connection string, I have first provided the server i.e. localdb and then provided name of the database i.e. TepDB and finally I have declared it a trusted connection.
- This MSSQLLocalDB is already available in Visual Studio and we will discuss it in detail in our coming lectures.
- When we upload our web application on a real server then we will change these server settings but for now, we will use localdb available.
Dependency Injection for DbContext class
- We have studied Dependency Injection in ASP.NET Core in detail, so now let's register TepDbContext class & provide SQL database connection string using Dependency Injection
- For that, open your startup.cs file and in ConfigureServices method, on IServicesCollection instance, we have called AddDbContextPool method, as shown in below figure:
- We have also specidified that we are using SQL Server & have provided the database connection string as well, I have placed a red boundary across it.
- In order to get the Connection string from appsettings.json file, I have injected IConfiguration using Constructor Injection and have placed a green boundary across it.
- So, our TepDBContext class is now registered with ASP.NET Core and we have also specified the Database provider & Connection String.
So, that was all for today. We have completed all our settings for database but we haven't yet created it. So, in our next lecture, we will see How to Create Database using EF Core Migrations. Till then take care & have fun !!!
Introduction to Entity Framework Core
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at detailed Introduction to Entity Framework Core. It's our 16th tutorial in ASP.NET Core series. So far, we have covered the the MVC architecture and few concepts related to object oriented programming and now we are ready to get our hands on Databases.
So, today we will cover data handling in detail, which is done by Entity Framework Core in .NET Core applications. So, let's first understand this Entity Framework Core:
Introduction to Entity Framework Core
- Entity Framework Core ( normally called EF Core ), designed by Microsoft, is an open source, flexible, extensible, lightweight and cross-platform framework, which is used for storing & retrieving data from database.
- EF Core creates a bridge between Objects in Programming & relational databases, thus referred as Object-Relational Mapper. ( O/RM )
- In simple words, EF Core acts as a middle layer between our .NET Core Application & database.
- EF Core is written from scratch for .NET Core, but also works with standard .NET 4.5+, and is an enhancement of ADO.NET.
Why need Entity Framework Core ?
- If you have worked on any database i.e. SQL, MYSQL, Oracle etc. then you must have the idea about query strings.
- In order to send or request data from these databases, we need to use query strings, which are normally quite lengthy and prone to errors.
- In order to avoid this direct interaction with databases using query strings, we have many third party frameworks which handle these underlying query strings themselves and provide programmers with easy programming methods to deal with the data.
- Entity Framework Core is an official data handling framework designed by Microsoft and works perfectly with ASP.NET Core.
- EF Core supports a wide range of relational database using third party libraries called database providers, we install these libraries as NuGet Packages.
- For example, if I want to work on SQL database, then I will install SQL NuGet Package, we will install one later.
EF Core Approach
- We can use two approaches in Entity Framework Core, which are:
- Code First Approach
- Database First Approach
- We have very limited support available for "Database First Approach" for now and we use this approach, when we already have the database. ( will cover it in future lectures )
- In Code First Approach, we design our database from scratch and using dbContext class, we transfer data from app to database & vice versa.
EF Core Package
- Now we need to select the type of database i.e. SQL, MYSQL, Oracle etc., which we want to use for our web application, so I am going to use Sql Database.
- In order to use SQL Database with EF Core, we need to install its NuGet Package called Microsoft.EntityFrameworkCore.SqlServer.
- This NuGet package is actually the Database provider, so if you are using any other database i.e. MYSQL, then you need to install its NuGet Package. ( We will install one in the next section )
- SQL Server NuGet Package has a dependency on EF Core Relational Package called Microsoft.EntityFrameworkCore.Relational.
- Relational package contains the functionality, that are common in all relational databases i.e. SQL, MYSQL, Oracle etc.
- This relational package, in turn has a dependency on Main EF Core Package called Microsoft.EntityFrameworkCore.
- That's the main base EF Core NuGet Package that will enable EF Core on our web App.
How to Install Entity Framework Core
- Now, let's install EF Core on our web application, so right click on the Project's Name in Solution Explorer.
- Now click on Manage NuGet Packages, and NuGet Package Manager will open up.
- In the Browser tab, make a search for EntityFrameworkCore.SqlServer and you will get results, as shown in below figure:
- You can see in above figure that first one appeared in the search, is our required NuGet Package, so let's install this one.
- As this SQL NuGet Package has a dependency on Relational, which in turn has dependency on EF Core, so when we install SQL Server Package, the other two will automatically be installed by the Visual Studio.
- So, click on the Install Button and then accept the terms and this SQL Server NuGet Package will be installed.
- After complete installation, you need to open Dependencies in Solution Explorer, as shown in figure on right side.
- You will find Packages in Dependencies, so open it up and inside it you will find our SQL Server NuGet Package.
- Expand this SQL Server Package and you will find its dependencies i.e. Relational etc.
- So, we have successfully installed Entity Framework Core for SQL Database on our web app.
So, that was all for today. We have successfully installed EF Core on our web application but we haven't yet created our SQL Database. In the next video, we will have a look at DbContext Class in Entity Framework Core. Till then take care & have fun !!!
Form Validation in ASP.NET Core
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at Form Validation in ASP.NET Core. It's our 15th tutorial in ASP.NET Core series. In our previous lecture, we have created a Registration Form for our engineering website. But we haven't added any validations on the submitted data.
So, even if users don't fill any boxes and just hit the Register Button, a new user will be created without any personal info. So, today we will place some checks on these text boxes to validate the user submitted data. So, let's get started with it:
Form Validation in ASP.NET Core
- Validations in ASP.NET Core are available in the form of attributes & Tag Helpers.
- Validation Attributes are applied on Properties in Model classes and validate the user submitted data.
- Validation Tag Helpers are used in Views and provide validation errors to the users.
- So, let's add few validations to our registration form and show errors, if inappropriate data is submitted.
Validation Attributes in ASP.NET Core
- ASP.NET Core has many builtin Validation Attributes to verify the incoming data, few of them are as follows:
- [Required] : Value is required.
- [Regular Expression] : Value must match the regular expression provided.
- [Compare] : Compares two properties i.e. Verify Email.
- [Range] : Value must lie between specified range.
- [MinLength] : Specifies the value's minimum length.
- [MaxLength] : Specifies the value's maximum length.
- [DataType] : Value must be of specified datatype.
- So, let's apply few of these Validation Attributes on our Properties in Engineers.cs file, placed in Models folder.
- We have already linked these properties with text boxes using asp-for Tag Helper.
- So, open this file & in Engineers class, place these validation attribute before properties, as shown in below figure:
- As you can see in above figure that before Username property, I have used two validation attributes i.e. Required & MaxLength.
- I have set the MaxLength to 50 and have also added a custom ErrorMessage.
- On the Email property, I have used Required & RegularExpression, this expression will verify the email format.
- On the FullName property, I have used Display attribute (it's not a validation attribute), and changed the name to "Full Name", it will change the label of this text box.
- Moreover, I have also made my enums properties null-able, as you can see I have placed ? sign infrom of DeptEnum & UniEnum. ( We will see later why null-able)
- We have added the validation attributes on our properties and now let's place a check in our Home Controllers class using builtin validation property.
Check if Data is Valid
- So, open you HomeController.cs class placed in the Controllers Folder.
- In HomeController class, we need to place validation check on the Registration action method of [HTTPPost] type, as this method is going to execute on pressing the Register button.
- As you can see in above code, I have placed an IF loop and have placed a Boolean property in it called ModelState.IsValid.
- This Boolean property will return TRUE, if there's no validation error & will return FALSE, if there's any validation error appeared.
- So, if it's true then I have added the submitted user data and displayed it in Info link by redirecting it to Info action method and if its FALSE, then simply returned the Registration View itself.
- One more thing to note here is that I have changed the return type of action method to IActionResult, as it contains both RedirectToAction() & View() result types.
Display Validation errors in ASP.NET Core
- Now it's time to display validation errors on the form itself, so now open your Registration.cshtml View file.
- Below each textbox, we need to add a <span> element, as shown in figure on right side.
- Inside this <span> element, I have use Validation Tag Helper named asp-validation-for and this Tag Helper is taking Username as a value.
- So, if there's any validation error appeared for Username, then it will be displayed here.
- Let's add this <span> element below all the textboxes, as shown in below figure:
- You can see in above figure, that I have placed <span> element containing asp-validation-for Tag Helper, below every input field.
- One more thing to note here is that I have added an option element Please Select, in both of my <select> tags, I have encircled them in above figure.
- Now let's run our application, and without entering any data, hit the Register button, and we will get validation errors, as shown in below figure:
- You can see in above figure that we are getting the Validation Error Messages for each component and at the end we have the summary of Validation errors.
- Moreover, for our Select boxes now we have a default option "Please Select", that's why we are getting Validation Errors for them as well, as now their value is null.
- If we select any option, then it will get value from the respective enum but in case of Please Select, its null-able and giving us Validation Error.
- We haven't added any Bootstrap design on these elements, as I want to keep things simple for now. ( We will design them later )
So, that was all for today. I hope you have enjoyed today's lecture. In next tutorial, we will have a look at detailed introduction to Entity Framework Core. Till then take care & have fun !!!
Create a Registration Form in ASP.NET Core
Hello friends, I hope you all are doing great. In today's tutorial, we will have a look at How to Create a Registration Form in ASP.NET Core. It's our 13th tutorial in ASP.NET Core series. In our previous lecture, we have seen How to use Tag Helpers in ASP.NET Core and have also discussed link, image & environment Tag Helpers.
Today, we will have a look at Form Tag Helpers and with their help we will design a simple Registration Form in ASP.NET Core. It will be a quite lengthy tutorial so if you got into any trouble, then ask in comments. So, let's create our Registration Form:
Create a Registration Form in ASP.NET Core
- Let's create a new action method named Registration, in our Home Controller class, as shown in figure on right side.
- I have also returned a View, so let's create a new Razor View in Views > Home folder and give it a name Registration.cshtml.
- This View is going to execute, when someone will open up this link: http://localhost:61745/home/registration
- So, let's create our registration Form in this Registration View file, as shown in below figure:
- It's a bit lengthy code, so let's understand this code, part by part. I have also added the Engineers.cs Code in red box for better understanding.
- I have first used @model directive and included Engineers class in this View file, as I want this user provided data to be linked with the properties of Engineers class.
- Next, I have given the Title for the Page which will be rendered to the Layout View file.
- Finally, I have used the <form> tag to create my Registration Form and I have used two Tag Helpers to provide the Controller & action method.
- So, when we will submit this form, then it will be redirected to the same page and I have also provided post method, So, this form will make a POST request, as shown in below figure:
- Inside this form, I have created label & input and have provided a tag helper asp-for.
- asp-for tag helper will link this input with the respective property in Engineers class.
- As you can see, I have provided Username to my first asp-for tag helper and we also have a Username property in my engineers class.
- Moreover, this asp-for tag helper will generate the Name & Id fields of this <input> tag, which you can check by looking at the source code of your webpage.
- As you can see in HTML output, we have for attribute in <label> tag and in <input> tag, we have name & id attributes.
- I have created 3 Labels & Text Boxes for their respective properties in engineers data class, i.e:
- Username.
- Email.
- FullName.
Enums in ASP.NET Core
- If you have studied C#, then you must be aware of C# Enums, so let's create two enums for our project.
- As our site is related to Engineering, so I want the registering users to provide their University & Department Names and for that I have created enums.
- We can place Emums anywhere in our project, so I have created a new folder in the root directory and named it TepEnums.
- Inside this folder, I have created two enums, named as:
- Inside these Enums, I have added few data and I am going to provide this data to my select elements in registration form, these enums are shown in below figure:
Select Tag Helpers in ASP.NET Core
- I have created 3 Textboxes at the start and then created two select element for Department & University.
- In this <select> tag, I have used asp-items tag helper and then provided it our newly created enum DeptEnum.
- I did the same with University <select> tag, so overall we are getting 5 values from our end user.
- Finally, at the end of our code, we have a Register button.
- Moreover, I have also changed the data type of University & Department from string to their respective enum, shown in the first figure of this tutorial.
Import Namespaces in Layout Imports File
- We have to include the namespaces of our enums in the Imports Layout File, so that we could use them in all of our Views.
- Similarly, as we are linking for Registration form with engineers class, which is present in Models folder, so we also have to include this Models Namespace, as shown in below figure:
- We have made all the changes and now it's time to run our web application and if everything goes fine, then you will get similar results:
- So, we have created our registration form but if you click on this Register Button, then it won't do anything except refreshing the page.
Create Method for adding New User
- We have created the font-end View for this registration form and have also created its action Method in Controller, but we haven't yet created it's model's function.
- So, let's open the IEngineersRepository.cs file in Models Folder and create a method in it for Adding New Engineer, using data coming from registration form, as show in figure on right side.
- We have declared the method in interface, so we have to provide its implementation as well in the EngineersRepository class, which is implementing this interface.
- So, open your EngineersRepository.cs file and inside this file, I have provided the implementation of AddNewEngineer() function.
- This function takes engineer as an input, which we will send it from Controllers class and when it gets this new engineers data, then we need to increment the id property, which has to be set internally.
- After that, I am adding this engineer variable in my _EngineersData array and finally returning the newly created engineer variable.
- So, we have successfully added the Model method for our Registration form, and when it will get the data, it will simply save it in the EngineerData array. ( We will save data in database in our coming lectures )
POST action method in ASP.NET Core
- Now open your HomeController.cs file, whcih has the action method Registration.
- This action method was used to open the Registration View but what will happen, when we press the Register button.
- When we press the REgister button, then HTML form will make a POST request so, let's create two method with same name i.e. Registration.
- First method will handle the HTTP Get request i.e. will simply display the Registration Form.
- Second method will handle the HTTP POST request and will execute on Register Button press, as shown in below figure:
- You can see in above figure, I have placed an [HTTPGet] attribute before first action method and thus it will simply serve the respective View file.
- While, I have placed [HTTPPost] attribute before second method and thus when we press the Register Button, a POST request will be generated and thus this action method will execute.
- In this Post method, I have simply executed the AddNewEngineer method of Model class, which will add this new engineer.
- Finally, I have redirected it to Info Page and have shown the details of newly created user.
- Now when you run your project, and add users' data using registration form then it's info page will open up with new engineer's data.
- I haven't added any Bootstrap code yet, as I want to keep things simple, we will design our application in future lectures.
So, that was all for today. So far, we haven't placed any validation check on our submitted data, we will do that in our next lecture. Till then take care & have fun !!!
HTML Tag Helpers in ASP.NET Core
Hello friends, I hope you all are doing great. In today's lecture, we will have a look at HTML Tag Helpers in ASP.NET Core. It's our 12th tutorial in ASP.NET Core series. If you have worked on ASP.NET then you must have been familiar with HTML Helpers. Tag Helpers are quite similar to HTML Helpers with slightest difference in its syntax.
Tag Helpers are new in ASP.NET Core and were not part of ASP.NET. So, let's first understand what are Tag Helpers & why we need to use them and at the end we will also discuss few common tag helpers in detail. So, let's get started with HTML Tag Helpers in ASP.NET Core:
HTML Tag Helpers in ASP.NET Core
- HTML Tag Helpers in ASP.NET Core are server side components and thus executed on the server to create HTML elements of the webpage.
- ASP.NET Core has a lot of built-in Tag Helpers for links, images, forms etc. available in Microsoft.AspNetCore.Mvc.TagHelpers assembly and we need to use @AddTagHelper directive to include them in Views.
- As we want to use these Tag Helpers in all of our Razor Views, so I am going to include this TagHelper assembly in _ViewImports.cshtml file, which we have created in 10th lecture and has all the assemblies importing statements.
- AS you can see in the figure on right side, I have imported Tag Helper assembly using @AddTagHelper directive and it has two parameters.
- I have added * in first parameter, which means I want to import all the Tag Helpers available in TagHelper assembly.
So, after adding this statement, we can now use Tag Helpers in our project. Let's have a look at few commonly used Tag Helpers:
HTML Tag Helpers for Hyperlinks
- In our Bootstrap lecture, we have added three <a> elements in our Info View file but haven't provided the href value.
- So, now let's use Tag Helpers to provide link value for href parameter of <a> tag, as shown in below figure:
- I have marked these 3 links with red box and you can see that I have used 3 link Tag Helpers i.e.
- asp-controller: I have provided the controllers name i.e. home.
- asp-action: I have provided the action method name i.e. Index for first link & Info for second.
- asp-route-id: I have provided the third parameter in it, while id is the name of the parameter.
- All Tag Helpers start with asp- prefix and are embedded in HTML tags as simple parameters.
- Now let's run this app and open this Info link and have a look at the HTML source, as shown in the below figure:
- I have encircled the output links with green box and you can see that we don't have any tag helpers in our output file.
- Instead, these tag helpers generated the HTML code of href parameter and we can see that the first link is of Homepage and the second link is of /Home/Info/3.
- Now, you must be wondering that why we need to use Tag Helpers, as we can easily add the hard coded links.
- The main benefit is, in future if you change your Controllers' names then your links will be changed and if you have placed them hard coded then you have to manually change them one by one.
- But with Tag Helpers, there's no need to change as they will get the update name of Controller or action method and will provide the corrected link.
- Moreover, Tag Helpers are inline with HTML unlike HTML Helpers and are thus easy to use.
HTML Tag Helper for Images
- If we change any existing image on our server without changing its link, the browser will keep on showing the old image, because of Browser Cache.
- So, in order to avoid that we need to use a builtin HTML Tag Helper called asp-append-version in <img> tag, as shown in below figure:
- So, now if the image content is changed on the server then it will make the new image available to the end user.
- If you check the HTML code of your output page, then you will find a unique string appended to your image link, which is calculated using the image content.
- So, if image content is changed then this string will also be calculated again and thus browser will know that there's new content in the image and will load it again from the server, instead of providing it from its cache.
HTML Tag Helper for Environments
- Using Environment Tag Helper, we can execute different content of the webpage, based on application environment.
- We have studied Environment variable in 5th lecture and have seen that we set this variable in lauchSettings.json file.
- In our Development Environment, we need to use non-minified versions of all of our third part client side libraries i.e. Bootstrap, Jquery, Javascript etc.
- But in Staging or Production Environment, we should use minified versions and for better performance, we should get them from their CDN networks.
- So, let's make these changes using Tag Helpers, open your _Layout.cshtml file, placed in Views > Shared folder.
- We have linked Bootstrap file with our project here, so let's add some code in it, as shown in below figure:
- You can see in above figure that in green box, I have placed the link to non-minified version of Bootstrap inside Environment tag helper and I have included Development Environment.
- So, this link will be used only when we are working in Development Environment.
- In the red box, I have excluded Development Environment, so this block will work for all Environments except Development.
- Inside this block, I have placed the Bootstrap CDN link, which you can get from its official site.
- But what if, this external CDN is link is down for some reason, then your server won't be able to fetch those files and thus your site won't work perfectly.
- In such cases, we should fall back to our own server and get the minified version of Bootstrap.
- So, let's add few more Tag Helpers to achieve that, as shown in below figure:
- As you can see in above figure, I have added five tag helpers in <link> tag.
- So if our application is unable to get the CDN link, then it will fallback to our own server & get the minified version of Bootstrap.
- These tag helpers are injecting a JavaScript code to check, whether we got the CDN link or not.
- As we have added this code in our Razor Layout file so it will be applied to all of our Views. ( We will add more Views in coming lectures )
So, that was all for today. I hope you have enjoyed today's lecture. In next tutorial, we will have a look at How to design Bootstrap navigation Menu in ASP.NET Core. Till then take care & have fun !!!