Andres Käver, IT Kolledž 2016. public interface IPersonRepository : IDisposable { IQueryable All { get; } IQueryable AllIncluding( params Expression.

Slides:



Advertisements
Similar presentations
CPSC 203 Introduction to Computers Lab 23 By Jie Gao.
Advertisements

LINQ and Collections An introduction to LINQ and Collections.
Class Scope class Student { private: string id; string firstName, lastName; float gpa; public: void Read() { cin >> id >> firstName >> lastName >> gpa;
Building Modern Websites with ASP.NET Rachel Appel
ORM Technologies and Entity Framework (EF)
Extension Methods Programming in C# Extension Methods CSE Prof. Roger Crawfis.
Connecting a.NET application to a database Jim Warren, COMPSCI 280 S Enterprise Software Development.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
Ics202 Data Structures. U n i v e r s i t y o f H a i l 1. Stacks top push (8)push (2)
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Testing Web Services Unit Testing, Data Layer Testing, Web API Controllers Testing, Integration Testing Web Services & Cloud SoftUni Team testing Technical.
CS 157B: Database Management Systems II January 30 Class Meeting Department of Computer Science San Jose State University Spring 2013 Instructor: Ron Mak.
Programming Progamz pls. Importance VERY IMPORTANT.
Interfaces. –An interface describes a set of methods: no constructors no instance variables –The interface must be implemented by some class. 646 java.
FEN UCN T&B - PBA/CodeContract- Intro 1 Code Contract Introduction Specification of a Person Class.
Features of Object Oriented Programming:  A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined.
ILM Proprietary and Confidential -
Introduction to Java Classes and Objects. What is a class A class is description of a structure that contains both data and methods – Describes a set.
ORM Technologies and Entity Framework (EF) ORM Concepts, Entity Framework, DbContext, CRUD Operations SoftUni Team Technical Trainers Software University.
1 Interfaces and Abstract Classes Chapter Objectives You will be able to: Write Interface definitions and class definitions that implement them.
Object Oriented Programming Generic Collections and LINQ Dr. Mike Spann
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 10 th Lecture Pavel Ježek
Generics Generics vs. heterogeneous collections Doing your own generics FEN 2014UCN Teknologi/act2learn1.
PRINCIPLES OF OBJECT ORIENTED DESIGN S.O.L.I.D. S.O.L.I.D Principles What is SOLID?  Acrostic of 5 Principles:  The Single Responsibility Principle.
 A class is a collection of things which posses common similarities.  In C#.NET a class is a user defined Data type and is Known as Reference.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
C# - Inheritance Ashima Wadhwa. Inheritance One of the most important concepts in object- oriented programming is inheritance. Inheritance allows us to.
Enum,Structure and Nullable Types Ashima Wadhwa. Enumerations, Enumerations, or enums, are used to group named constants similar to how they are used.
ASP.NET MVC Tutoriál. Obsah Založení projektu, přidání databáze Model Controllery, Routing a Pohledy Práce s daty (CRUD) Unit testy a Dependency injection.
Writing Better C# Using C# 6 By: Mitchel Sellers.
Lecture 11: Generics. The Generic List loading data from a file using System.IO; : namespace EmpListDemo { static class Program { static void Main(string[]
Exception Handling SWE 344 Internet Protocols & Client Server Programming.
Neo.NET Entity Objects Architecture and Implementation Copyright © Erik Dörnenburg – Last updated: December 2004.
Chapter 5 Classes Essential C# Mark Michaelis Ch. 51 Excerpted from Essential C# 4.0 by Mark Michaelis (ISBN: ). Copyright 2010 Pearson Education,
Repository muster – vol2 Mait Poska & Andres Käver, IT Kolledž 2015.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 2 nd Lecture Pavel Ježek
Build Data Driven Apps with ASP.NET Core Rachel Appel.
Building Web Applications with Microsoft ASP
Introduction to Entity framework
Building Web Applications with Microsoft ASP
Introduction to Entity Framework
Advanced .NET Programming I 2nd Lecture
ASP.NET Unit Testing Unit Testing Web API SoftUni Team ASP.NET
TESTING TEST DRIVEN DEVELOPMENT
Lecture 6 Object Oriented Programming Using Java
EF Advanced Querying Optimize Performance SoftUni Team Advanced
BİL527 – Bilgisayar Programlama I
using System; namespace Demo01 { class Program
Best practices and architecture
Dependency Injection Andres Käver, IT College 2016/2017 Spring.
New Features of C# Kuppurasu Nagaraj Microsoft Connect 2016
Factory pattern Unit of Work
Entity Framework Advanced Querying SoftUni Team Technical Trainers
Herding Nulls and other C# stories from the future
Initializing Arrays char [] cArray3 = {'a', 'b', 'c'};
Functions Used to write code only once Can use parameters.
Classes Variables That Are Not of a Built-in Type Are Objects
null, true, and false are also reserved.
Repository pattern Andres Käver, IT Kolledž 2016/2017 Spring.
Exception Handling CSCI293 - C# October 3, 2005.
عرض اجمالي المهام الشرطية في سي شارب (الأمر if)
Assignment 7 User Defined Classes Part 2
Recursive GCD Demo public class Euclid {
CS/ENGRD 2110 Fall 2018 Lecture 5: Local vars; Inside-out rule; constructors
class PrintOnetoTen { public static void main(String args[]) {
IT College 2016, Andres käver
Module 2 Variables, Assignment, and Data Types
C# - EF Core Intro IT College, Andres Käver, , Fall semester
C# - Razor Pages Db/Scaffolding/Async
CSG2H3 Object Oriented Programming
Presentation transcript:

Andres Käver, IT Kolledž 2016

public interface IPersonRepository : IDisposable { IQueryable All { get; } IQueryable AllIncluding( params Expression >[] includeProperties); Person Find(int id); void InsertOrUpdate(Person person); void Delete(int id); void Save(); }

public class PersonRepository : IPersonRepository { ContactContext context = new ContactContext(); public IQueryable All { get { return context.People; } } public IQueryable AllIncluding( params Expression >[] includeProperties) { IQueryable query = context.People; foreach (var includeProperty in includeProperties) { query = query.Include(includeProperty); } return query; } public Person Find(int id){ return context.People.Find(id); } public void InsertOrUpdate(Person person) { if (person.PersonID == default(int)) { // New entity context.People.Add(person); } else { // Existing entity context.Entry(person).State = EntityState.Modified; } public void Delete(int id){ var person = context.People.Find(id); context.People.Remove(person); } public void Save() { context.SaveChanges(); } public void Dispose() { context.Dispose(); }

using ContactsLibrary; namespace RepoConsoleApp { class Program { static void Main(string[] args) { using (var repo = new PersonRepository()) { repo.InsertOrUpdate(new Person { FirstName = "Juku", LastName = "Mänd" }); repo.InsertOrUpdate(new Person { FirstName = "Malle", LastName = "Tamm" }); repo.Save(); foreach (var person in repo.All.ToList()) { Console.WriteLine("{0} {1}", person.FirstName, person.LastName); } Console.ReadLine(); }

public interface IEntityRepository : IDisposable { IQueryable All { get; } IQueryable AllIncluding(params Expression >[] includeProperties); T Find(int id); void InsertOrUpdate(T entity); void Delete(int id); void Save(); } public interface IPersonRepository : IEntityRepository { }

// this is the base repository interface for all EF repositories public interface IEFRepository : IDisposable where T : class { // get all records in table IQueryable All { get; } // get all records with filter IQueryable GetAllIncluding (params Expression >[] includeProperties); T GetById(int id); void Add(T entity); void Update(T entity); void Delete(T entity); void Delete(int id); void Save(); }

// this is universal base EF repository implementation, to be included in all other repos // covers all basic crud methods, common for all other repos public class EFRepository : IEFRepository where T : class { // the context and the dbset we are working with protected DbContext DbContext { get; set; } protected DbSet DbSet { get; set; } //Constructor, requires dbContext as dependency public EFRepository(DbContext dbContext) { if (dbContext == null) throw new ArgumentNullException("dbContext"); DbContext = dbContext; //get the dbset from context DbSet = DbContext.Set (); } public IQueryable All { get { return DbSet; } }......

interface IPersonRepository : IEFRepository { } public class PersonRepository : EFRepository, IPersonRepository { public PersonRepository(DbContext context) : base(context) { }