Code Monkey home page Code Monkey logo

data_access's Introduction

Data_Access

Data access is a computer program that simply provides access to data stored in a consistent repository, an example of an entity-relationship database to this consistent repository.

ORM

Object-Relational Mapping (ORM) is a technique that allows you to query and manipulate data from a database using the Object-oriented paradigm. It acts as a bridge between the database and the application. It is a structure that performs all database operations without the need for the application to access the database directly, by converting the tables in the database to classes, columns to properties, and records to objects.

Advantages of using an ORM

  • It gives the opportunity to write code in accordance with object-oriented programming standards.
  • It provides the opportunity to perform database operations with minimum SQL knowledge.
  • There is no database platform dependency.
  • It reduces the time to write code.
  • Increases code readability.

Disadvantages of using an ORM

  • It is slower in performance compared to manual coding.
  • Since the database is modeled on objects, there is a connection between objects. There is a situation where the connection is disrupted by unconscious interventions.
  • For first-time beginners, the syntax may be different.

An ORM use case

  • With hand coding
string sql = "SELECT FirstName FROM Accounts WHERE Id = 7";
DbCommand cmd = new DbCommand(connection, sql);
Result result = cmd.Execute();
string firstName = result[0]["FirstName"];
  • With using an ORM tool
Account user = repository.GetAccount(7);
string name= user.FirstName;

Frequently used ORM technologies by language

  • C#: Entity Framework, Dapper, ECO, XPO, Norm
  • Java: Hibernate, Ebean, Torque, JPA,MyBattis *Php: CakePHP, Codelgniter, RedBean, Doctrine,Propel, PdoMap
  • Python: Django, South,Storm

Entity Framework

Entity Framework is an open-source ORM framework for .NET applications supported by Microsoft. It enables developers to work with data using objects of domain specific classes without focusing on the underlying database tables and columns where this data is stored. With the Entity Framework, developers can work at a higher level of abstraction when they deal with data, and can create and maintain data-oriented applications with less code compared with traditional applications.

alt text for screen readers.

Entity Approaches

1. Database First

In this approach, the priority is on the database. First, the database is created, then the coding side is started.

2. Code First

Bu yaklaşımda design işlemlerinden çok kod yazma ön plandadır. Veritabanı işlemleri design işlemleri olarak değilde kod yazarak gerçekleştirilir. Geliştirici veritabanıyla ilgili tüm işlemleri kodlayarak oluşturur. Bu yaklaşımda hakimiyet tamamen sizdedir.

3. Model First

If you don't have a database, you can create a model directly from visual studio. In order to introduce the changes we have made here to sql, we need to click generate database from.

Dapper

Dapper is a simple object mapper for .NET and owns the title of King of Micro ORM in terms of speed and is virtually as fast as using a raw ADO.NET data reader. An ORM is an Object Relational Mapper, which is responsible for mapping between database and programming language.

alt text for screen readers

How Dapper Works?

It is a three-step process.

  • Create an IDbConnection object.
  • Write a query to perform CRUD operations.
  • Pass query as a parameter in the Execute method.

SQL commands can be used easily with Dapper.

string sql = "INSERT INTO Customers (CustomerName) Values (@CustomerName);";

   var affectedRows = connection.Execute(sql, new {CustomerName = "Mark"});

   Console.WriteLine(affectedRows);


In addition, stored procedures and dynamically using parameters are also very functional.

 if (db.State==ConnectionState.Closed)
            {
                db.Open();

                //the parameters of stored procedure and ones inside param have to be same
                DynamicParameters param = new DynamicParameters();
                param.Add("@contactid", contactId);
                param.Add("@name", txtName.Text.Trim());
                param.Add("number",txtNumber.Text.Trim());
                db.Execute("up_ContactAddOrEdit",param,commandType:CommandType.StoredProcedure);

                if (contactId==0)
                {
                    MessageBox.Show("Saved Succesfully");

                }
                else
                {
                    MessageBox.Show("Updated Succesfully");

                }
                GetAllContacts();
                Eraser(txtName, txtNumber);

            }

data_access's People

Contributors

kadir-code avatar xkadir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

data_access's Issues

Hi Kadir

hi kadir, your solid principle work is quite nice. For this reason i want to ask something. I use repository in my project, but i consider to repository pattern does it comply with solid principles?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.