Monday, September 16, 2013

Inserting New Data using ADO.NET ENTITY FRAMEWORK

ADO.NET ENTITY FRAMEWORK WITH PARENT CHILD TABLE USING CONSOLE APPLICATION.

    Generating Model from Database


File->New project


·        In the Solution Explorer right-click on the project and choose Add | New Item.

·        In the dialog choose ADO.NET Entity Data Model, click Add. This launches Entity Data Model Wizard.


·        In the wizard choose Generate from database, click next.


Click on New Connection.




Click on Next Button. 



Select the tables and click on finish.

Go to Program.cs and write the following code 




    output





Sunday, September 15, 2013

ADO.NET ENTITY FRAMEWORK WITH PARENT CHILD TABLE USING CONSOLE APPLICATION


   Generating Model from Database

File->New project




·        In the Solution Explorer right-click on the project and choose Add | New Item.

·        In the dialog choose ADO.NET Entity Data Model, click Add. This launches Entity Data Model Wizard.
And click on add



·        In the wizard choose Generate from database, click next.

     
    Click on New Connection.



Click on OK Button.


Click on Next Button. 


Select the tables and click on finish.



Go to Program.cs and write the following code 


Output

ADO.NET ENTITY FRAMEWORK EXAMPLE 1(with single table)

Example 1:

Generating Model from Database

File->New project




·        In the Solution Explorer right-click on the project and choose Add | New Item.


·        In the dialog choose ADO.NET Entity Data Model, click Add. This launches Entity Data Model Wizard.



Click on New Connection.



Click on OK Button.



Click on Next Button. 


select the table and click on finish.


Go to Program.cs and write the following code 



Output 




MYDBEntities

Is the name of the class that knows all about your model and does everything to handle it.Entity Framework operations are performed within this class's properties and methods. It is recommended that you keep a single instance of the class throughout your application because it consumes lots of resources.
·         Queryit - these are arbitrary variable names in the LINQ to Entities statement. The former is used as the collection of data objects, the latter is not used outside the statement.
·         Emp (in the for each statement) is the name of an auto generated class. This class maps to the company table in the database and is named after it.











Saturday, September 14, 2013

ADO.NET Entity FrameWork

Introduction to Entity Framework ?

All these years, Microsoft has been providing different ways to communicate with the Database. Developers have been switching from one data access technology to the other, starting with DAO (Data Access Objects), then RDO (Remote Data Objects), then ADO (ActiveX Data Objects) and then finally ADO.NET.

The ADO.NET Entity Framework (EF) is an Object/Relational mapping (ORM) framework and is a set of technologies in ADO.NET, for developing applications that interacts with data. ADO.NET developer spends a lot of time keeping up with the database changes. Well EF provides a mapping from the relational database schema to the objects and offers an abstraction of ADO.NET.
So with EF, you can define Entity classes that are independent of a database structure and then map them to the tables and associations of the database.
Entity Framework is actually written on top of ADO.NET, meaning under this framework, we are still using ADO.NET. So we cannot say that Entity Framework is a replacement of ADO.NET.

ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational database. It enabling developers to deal with data as objects and properties.Using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as strongly typed objects using C# or VB.Net.

What happens to ADO.NET now?
EF was not released with the intension to replace ADO.NET. It is in fact an enhancement to ADO.NET and helps eliminate the gap between the application and the database. Behind the scene, EF uses ADO.NET classes, but the details are abstracted from you. EF provides a shift from Database-oriented (Data Reader, Dataset) to Model-oriented development. So instead of focusing on a Database, a developer focuses on the Entity that represents the Business Model of the application.

When was Entity Framework Released?

Although announced in TechEd 2006, the first version of Entity Framework 3.5 was released two years later in August 2008, along with Visual Studio 2008 SP1 and .NET 3.5 SP1.
The second version (also the current version) of Entity Framework i.e. 4.0 was released in April 2010 along with VS 2010 and .NET 4.0.

What happened to LINQ to SQL?

When .NET 3.5 and Visual Studio 2008 was being released in November 2007, a lot of focus was on LINQ. The original plan was to release EF along with VS 2008/.NET 3.5 and introduce developers to this new LINQ based data access technology. However the scale of EF caused a delay and it could not be released along with VS 2008.

Finally when EF 3.5 was released in August 2008, it could not get the attention from the developer community, for obvious reasons. L2S was gaining popularity primarily due to it being lightweight, simple and easy to use technology and the fact that most of the .NET apps targeted SQL Server, there was a resistance to adopt a new framework (EF) from the dev community. EF remained a misunderstood technology, there were issues in the framework and although accidental, L2S was still believed by many as the original LINQ provider for data access. EF had a lot to prove!

However with the release of EF 4.0 with .NET 4.0, things have changed, including opinions. Microsoft made it clear that although L2S was supported, it was not the recommended technology. Moreover with the new features like POCO support, Model First Development and Custom Code Generation, developers started looking at EF 4.0 and consider it seriously as the preferred ORM solution for enterprise apps.

Advantages of Entity Framework: 

There are lot of reason why should you use entity framework over LinqToSql and ADO.NET.

1.     Database performance is improved. Updating your EDM based on your DB changes would take less time rather than the conventional methods. Database operations like select, insert, update, delete will work faster as you don't have to hit database again and again as you would be working with objects not with database tables.

2.     Entity Framework performing basic CRUD (Create, Read, Update, Delete) operations. So most of the time you don't have to write any SQL yourself. When you make any changes to the object, the ORM will usually detect this, and mark the object as 'modified'. When you save all the changes in your ORM to the database, the ORM will automatically generate insert/update/delete statements, based on what you did with the objects.

3.     Entity Framework works on databases other than Microsoft SQL Server, like Oracle, MySQL etc. While Linq is limited to MS SQL Server. It is easy to add support for another database (like Oracle) as we are programming against a model.

Easily managing "1 to 1", "1 to many", and "many to many" relationships.

Ability to have inheritance relationships between entities.


Microsoft Definition.


The Microsoft ADO.NET Entity Framework is an Object/Relational Mapping (ORM) framework that enables developers to work with relational data as domain-specific objects, eliminating the need for most of the data access plumbing code that developers usually need to write. Using the Entity Framework, developers issue queries using LINQ, then retrieve and manipulate data as strongly typed objects. The Entity Framework’s ORM implementation provides services like change tracking, identity resolution, lazy loading, and query translation so that developers can focus on their application-specific business logic rather than the data access fundamentals. 

We can simple say as

Entity framework is an Object/Relational Mapping (O/RM) framework. It is an enhancement to ADO.NET that gives developers an automated mechanism for accessing & storing the data in the database and working with the results in addition to Data Reader and Dataset.

What is ORM
The term “Object-Relational Mapping” (ORM) refers to the technique of mapping a data representation, from an object model, to a relational data model with SQL-based schema.



Sunday, September 1, 2013

WCF WITH CONSOLE

Example 1:

WCF SERVICE WITH CONSOLE (Run visual studio as Admin)



File->New-> Project (select console application) using http binding


And add new item


Right click on the project Name and select  Add Reference


 Add the Reference àSystem.ServiceModel.dll


WCF always recommends interface pattern for defining contract for user
So Add New Item ->Create Interface with required methods and then Add WCF Attributes to it


.
and write the following code.




And again add new item  and give the name as Demo.cs and inherit the Job.cs file.
And write the following code.




And go to program.cs and write the following code.


Now service is ready. And select start debugging & see the output



Note: when running client application service should be running.   

Client Application.

 File->New-> Project 



And write the following code in Program.cs as below



And run the program and see the output. First run Service and make sure that service is running and then run the client application.


Kubernetes

Prerequisites We assume anyone who wants to understand Kubernetes should have an understating of how the Docker works, how the Docker images...