ADO.Net Entity Framework Library | ADO.NET Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello welcome to nourish technologies this is the kur Sharma we are continuing our the session of a do dotnet entity framework in our previous sessions of a do dotnet entity framework we discussed about what is a do dotnet entity framework what are the key features of a do dotnet entity framework and how entity framework architecture works means we discussed about the framework architecture what are all the components of entity framework and how it works after understanding all these concepts now we have to discuss about what is the library library for entity framework we have to discuss about the library for entity framework means in order to use the various approaches provided by a do dotnet entity framework as already we discussed that entity framework provides three different approaches code first approach database first approach and model first in order to handle all these three types of approaches we have to use the base library provided by the entity framework actually entity framework requires two important libraries one is defined under system dot data dot entity another one is a system dot component model component model in order to deal with entity framework we need two important libraries one entity library another one component model this data dot entity namespace it will provide some important classes like we have dbcontext we have a DB set and we have data base what is the role of these be context D be set and database we will see and component model it comprises of some set of attributes these attributes are responsible for representing the data we are working with entity library provides all the classes which are responsible for communicating with the database connecting with the database reading the data from database changing updating deleting all such operations are supported under the library system dot data dot entity and component model will provide a set of attributes that are used to represent the data we are working with that means we discussed that in entity framework we write according to the business requirement that means we are not writing for the database we are ready writing for the domain-specific classes in that situation the question is how our business classes are going to map with the database tables you are saying that you can communicate with the database tables by using your domain-specific classes then how these classes are mapping towards those tables for that we need some set of attributes this all attributes are defined under this component model the attributes in the component model are categorized into two types again we have schema attributes another one we have moral attributes before going into the concept of what is a schema attribute and model attributes about component model first we will discuss about this entity library so in order to deal with entity framework in our area dotnet we have to use two important libraries one is entity library another one component model library entity library provides the classes dbcontext DB set and database component model will provide some set of attributes which are categorized into schema attributes and model attributes first we will take a look about what is this entity library the entity library comprises of three important classes one is DB context DB set and database DB context is a class which is using a DB connection it is using a DB connection DB context is a class which is using a DB connection generally DB connection is already being used by your SQL connection oledb connection o DB connection in the general ad or dotnet all the connection classes are implemented from a DB connection and here entity framework in entity framework DB context is using a DB connection that means an object of DB context is responsible for connecting with the database that means how you can connect with database how you can connect with the database generally DB connection will use a connection string through which it will connect to the specific data source and this DB connection is being used by the DB context of entity framework so what is DB context class in entity framework DB context class will provide some set of attributes some set of properties and methods through which you can connect with the database DB context is responsible for various operations like track changing query translation object materializations all such activities are handled by using a dbcontext so in entity framework one important class is the dbcontext class dbcontext class is responsible for communicating with the database connecting with the database open the connection close the connection transactions all these are handled by using the connect dbcontext class so then what is adb cetera actually the DB context is a collection of DB sets it will connect with the database and also it will configure a collection of DB set and each DB set each DB set will represent an entity that means it will represent the tables you are working with now you can read and write the values into the tables by using the DB set a DB set will provide some set of properties through which you can read and write values into the entities so every entity is representing a table in the database so DB context will connect with the database and DB set will be responsible for interacting with the tables inside the database and all these DB sets are accessible with the reference of DB context because DB context is a collection of DB set so context will connect with the datasource and DB set will be responsible for reading and writing the values into the entity here entity is the table means communicating with the database table is managed by using TV set and database database is a class in entity framework which defines the strategy which defines the strategy as we already discussed that there are various strategies in entity framework like whether to create the database for your logic or use an existing database whether to drop the database every time and add the new features whether to keep the database and allow the changes all such strategies are defined by using database so whenever you are using entity framework it is very important to define the strategy strategy will tell whether to create the database or to use the existing database and you can configure the strategies for entity framework by using database so entity framework will provide the libraries system dot data dot entity with three important classes dbcontext DB set and database dbcontext object is responsible for connecting with the datasource and DB set is responsible for representing the tables that is entities so that we can read and write values into the tables and database is a class which defines the strategy so all these classes are defined in system dot data dot entity now another important library that we need in AD or dotnet entity framework is the component model library what is component model component model is nothing but component model will provide some annotations these annotations are responsible for representing the Poco classes we call the classes as poco plain old CLR objects poco classes poco classes are nothing but poco classes are domain specific poco classes are domain specific classes that means in entity framework we are saying that dotnet developers will eliminate most of the data access code and they will always now write for the domain specific means a business requirement in that situation now very important is our c-sharp classes must represent a database table we are working with and they must be to the database table so that they can interact with the table so here the point is how your c-sharp class is mapped to a database table how the fields in the class are napa to the fields inside the database table that is handled by using the library component model it will provide a set of attributes that are categorized into two types we have schema attributes we have schema attributes these schema attributes are defined under the namespace system dot component model model dot data annotations data annotations dot schema schema so the namespace system dot component model dot data annotations dot schema this namespace will provide this namespace will provide the attributes which are responsible for defining the structure of the table schema means we know that schema defines the structure that means schema contains attributes that are used to define the table structure and what are the important attributes in available in the schema one we have a table we have a column and another we have a foreign key foreign key so these three are very important attributes which are defined under the component model data annotations dot schema that means if you are creating a c-sharp class and you want this class to map to the database tables then you have to design the class as per the structure of the table table name field name data types all these must be defined according to the structure of the database table then for that we can use these attributes so schema attributes of component model are responsible for defining the structure of the table that you are working with how I will show you just basic overview for example we have a class class by name some product and this class is having some members like public int correct ID it is a simple attribute so just it gets it accessor for that and we have a public string name and it gets set accessor for this now we have a public decimal decimal price and it gets set accessor here now very important is how this c-sharp class is going to map with a database table for example in the database we have a table called TBL products now this class should map to the stable TBL products then we have to mark this class with an attribute table and this table attribute will tell to which database table it should be mapped to that is some TBL 4x so the class product is now mapped to a database table called TBL products so it represents the database table called TBL products similarly if I want the name or datatype for the field to be defined like product ID or name or price by default these properties are directly mapped to the database table fields if you want to define a different name for the field if you want to define a different data type for the field that you can define by using the attribute called column so column is an table is an attribute the table attribute is responsible for mapping you c-sharp class to a database table column is an attribute which is responsible for mapping your properties to a database field column and foreign key is an attribute which is used as a navigation property in your class so that it will map to the foreign key attribute available in your database table so schema attributes three important attributes are their table column and foreign key table is used to wrap to a database table column is used to map to a database table column and foreign key is for the navigation property it maps to the foreign key in the table so these are schema annotations so component model contains schema annotations which are responsible for mapping our c-sharp class to a database table it is responsible for structuring it now we have another set of annotations and we call them as model annotations model annotations are defined under system dot component model component model dot data annotations annotations so we have two sets one component model dot data annotation stock schema and another one we have data annotations now this data annotations will provide some set of properties which are used to define the behavior of the model fields that means when you are designing your domain-specific classes whatever the properties you defined in the class that means in our previous class we designed the product ID name and decimal now if they are mapping towards a database field then we have to set some restrictions for the database field such as like now I want my data my c-sharp class property to be a primary key it should map to a primary key to the data stable then we have to use an attribute key there is another attribute required we have an attribute max length max length we have an attribute min length min length we have an attribute as string length string length by using these attributes by using these attributes you can define the behavior of the model fields that means whenever you design a domain-specific class and you want this class to be mapped to the database table in the database table the fields may have some restrictions and we want our columns to be mapped with these properties present inside the class in that situation how you can designate a primary key how you will designate a required field how you will designate the minimum and maximum number of characters can be entered into the field that you can define by using the model annotations so what is key key is a property which will map to the primary key of the database table for example in this class suppose I want the product ID to be the primary key of the table then I need to designate this with an attribute key later in practical approach while dealing with the various code first model first approaches we will practically implement this and see how it creates or maps to the primary key so it is just an overview of how do we designate our classes that can interact with the model our database tables so key is an attribute which will map to the primary key similarly now I want the name to be mandatory that means generally in database we have a database table we have a field name and that field name is a nullable type or you want to make it mandatory then you have to designate it as an honourable type if M is an honourable type here you are representing the name as a string type in C sharp but C sharp string type is nullable and in your database you are saying that it is non nullable then how I can make this nullable type as non malleable type then we can mark this with an attribute called required this indicates that this field must have a value and it cannot be empty so such attributes can be defined by using the annotations so what is the minimum and maximum length of characters can be entered so the string length will define the minimum and maximum length of characters can be entered so data annotations comprises of two sets of attributes one we have schema attributes which are responsible for defining the structure of the table and three important schema attributes are there table column and foreign key and we have model annotations model annotations are used to define the restrictions and behavior of the fields that means database table fields and what are the important attributes we have key required max length string length like attributes these are all defined under the library component model dot data annotations and schema attributes are defined under data annotations dot schema so finally to deal with entity framework we need two libraries one the entity library and the component model let us see the summary of the classes which are required for entity framework so we need a three important namespaces one is system dot data dot entity it provides the classes one dbcontext another 1db set under one data base we need another library system dot component model component model dot data annotations data annotations dot schema schema it will right three important attributes we have a table attribute we have a column attribute and we have a foreign key attribute foreign key attribute we have another system dot component model component model dot data annotations data annotations it will provide attributes like key and required and max length and string length string length these are the important attributes and the namespaces that are required to deal with entity framework now after understanding the library what is required for entity framework now we will practically see the various approaches how we can interact with entity frame database and tables by using a do dotnet entity framework in the next session of entity framework we will see the practical approach of how do we work with code first approach in a do dotnet thank you
Info
Channel: Naresh i Technologies
Views: 13,730
Rating: undefined out of 5
Keywords: ASP.NET, Sudhakar Sharma, Naresh IT, ADO.Net Entity Framework, Hands on ADO.NET Training, ADO.NET Demo, Online ADO.NET Training, ADO.NET Tutorial Videos, ADO.NET Overview, ADO.NET Interview Questions
Id: E7WR6fN2BjI
Channel Id: undefined
Length: 23min 45sec (1425 seconds)
Published: Mon Sep 19 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.