Entity Framework
Entity Framework
Entity Framework
NET:
ADO.NET and ASP.NET are two different technologies used in .NET development, with
different purposes and functionalities.
ADO.NET is a data access technology that provides a set of classes and interfaces to
interact with various data sources such as databases, XML files, and web services. It is
used to access and manipulate data from databases and other data sources using a set of
objects and classes such as Connection, Command, DataReader, DataSet, and
DataAdapter. ADO.NET provides a low-level access to data and requires more coding
effort to manage data access.
ASP.NET, on the other hand, is a web application framework used to build dynamic web
applications and web services. It provides a set of libraries and tools for building web
applications, including web forms, MVC, and web API. ASP.NET provides a high-level
abstraction over HTTP and allows developers to build web applications using the
Model-View-Controller (MVC) pattern. It includes a set of controls and components that
simplify web development, such as server controls, validation controls, and
authentication controls.
In summary, ADO.NET is a data access technology used to access and manipulate data
from various data sources, while ASP.NET is a web application framework used to build
web applications and services.
Entity Framework:
Entity Framework (EF) is an object-relational mapping (ORM) framework for .NET
applications. It is a set of libraries and tools that enable developers to work with data in
a database using .NET objects. EF simplifies data access by providing an abstraction
layer over the database schema, allowing developers to work with high-level domain-
specific objects instead of low-level database tables and columns.
The Entity Framework is built on top of ADO.NET, which provides low-level access to
data. It supports various databases such as SQL Server, MySQL, Oracle, and PostgreSQL,
and it allows developers to use LINQ to query data.
EF provides various features such as change tracking, lazy loading, and automatic code
generation. It also provides support for transactions, concurrency, and stored
procedures.
ORM in C#:
In C#, ORM stands for Object-Relational Mapping. It's a programming technique used to
map objects from object-oriented programming languages like C# to relational database
tables.
With ORM, developers can interact with databases using objects and classes, which
makes database operations simpler and closely aligned with the object-oriented
principles of the programming language.
<connectionStrings>
<add name="TestConnection" providerName="System.Data.SqlClient"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=TestDB;Integrated
Security=true" />
</connectionStrings>
Create a Class file StudentDetails.cs with below entities and Data context
<div>
<table border="0" cellspacing="2" cellpadding="2" style="padding:5px">
<tr>
<td colspan="2">Add Student Details
</td>
</tr>
<tr>
<td>Student Name
</td>
<td>
<asp:TextBox ID="txtStudentName" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
Age
</td>
<td>
<asp:TextBox ID="txtAge" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td></td>
<td>
<asp:Button ID="btnSave" runat="server" Text="Save"
OnClick="btnSave_Click" />
<asp:Button ID="btnUpdate" runat="server" Text="Update"
OnClick="btnUpdate_Click" />
<asp:HiddenField ID="hfId" runat="server" />
</td>
</tr>
</table>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<<td colspan="3">
<asp:GridView ID="grvStudentDetails" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="Id" DataField="Id" />
<asp:BoundField HeaderText="Student Name"
DataField="StudentName" />
<asp:BoundField HeaderText="Age" DataField="Age" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Edit"
OnClick="btnEdit_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
}
btnSave.Visible = false;
btnUpdate.Visible = true;
}