Modeling, API, tools and best practices Viktor Zhivkov Telerik Software Academy Senior Software Developer, OpenAccess ORM.

Slides:



Advertisements
Similar presentations
Introduction to NHibernate By Andrew Smith. The Basics Object Relation Mapper Maps POCOs to database tables Based on Java Hibernate. V stable Generates.
Advertisements

NHibernate Object/Relational Persistence for.NET.
.NET Database Technologies: Open-Source Frameworks.
1 Chapter 12 Working With Access 2000 on the Internet.
Fast Track to ColdFusion 9. Getting Started with ColdFusion Understanding Dynamic Web Pages ColdFusion Benchmark Introducing the ColdFusion Language Introducing.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
1 Chapter Overview Transferring and Transforming Data Introducing Microsoft Data Transformation Services (DTS) Transferring and Transforming Data with.
Discover, Master, InfluenceSlide 1 SQL Server Compact Edition and the Entity Framework Rob Sanders Readify.
Microsoft ® Official Course Monitoring and Troubleshooting Custom SharePoint Solutions SharePoint Practice Microsoft SharePoint 2013.
Esri International User Conference | San Diego, CA Technical Workshops | Managing and Editing Annotation Natalie Vines Samantha Keehan July 14, 2011.
Data-tier Application, Import, Refactoring, Publish, Schema Comparison, Database Unit Testing Borislav Statev Telerik Software Academy academy.telerik.com.
Object Oriented Databases by Adam Stevenson. Object Databases Became commercially popular in mid 1990’s Became commercially popular in mid 1990’s You.
Creating and Running Your First C# Program Telerik Software Academy Telerik School Academy.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Integrated Development Environment Building Your First Project (A Step-By-Step Approach)
Architecture Of ASP.NET. What is ASP?  Server-side scripting technology.  Files containing HTML and scripting code.  Access via HTTP requests.  Scripting.
WaveMaker Visual AJAX Studio 4.0 Training Troubleshooting.
Entity Framework Code First End to End
.NET Database Technologies: Entity Framework additional notes – part 2.
9 Chapter Nine Extracting and Transforming Data with SQL Server 2000.
RIA Services Master Class Presenter: Kevin Grossnicklaus November 30 th, 2010.
NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image. WEB.
® IBM Software Group © 2009 IBM Corporation Rational Publishing Engine RQM Multi Level Report Tutorial David Rennie, IBM Rational Services A/NZ
Moving into the Testing Phase Revised for October 22, 2008.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
NHibernate in Action Web Seminar at UMLChina By Pierre Henri Kuaté 2008/08/27
CHAPTER 14 USING RELATIONAL DATABASES TO PROVIDE OBJECT PERSISTENCE (ONLINE) © 2013 Pearson Education, Inc. Publishing as Prentice Hall 1 Modern Database.
Winrunner Usage - Best Practices S.A.Christopher.
Chapter 6 SAS ® OLAP Cube Studio. Section 6.1 SAS OLAP Cube Studio Architecture.
Introduction to Entity Framework Part 2 CRUD Scaffolding Tom Perkins NTPCUG.
Oracle Data Integrator Procedures, Advanced Workflows.
What’s new in Kentico CMS 5.0 Michal Neuwirth Product Manager Kentico Software.
Object Oriented Software Development 10. Persistent Storage.
Efficient RDF Storage and Retrieval in Jena2 Written by: Kevin Wilkinson, Craig Sayers, Harumi Kuno, Dave Reynolds Presented by: Umer Fareed 파리드.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Ventsislav Popov Crossroad Ltd.. 1. ASP.NET Data Source Controls  SqlDataSource  EntityDataSource  ObjectDataSource 2. Entity Data Model and ADO.NET.
© 2008 Hewlett-Packard Development Company, L.P. The information contained herein is subject to change without notice Lesson # 9 HP UCMDB 8.0 Essentials.
REpresentational State Transfer.  Resources  Representations  Verbs  Links  Headers  HTTP Status Codes.
SOAP-based Web Services Telerik Software Academy Software Quality Assurance.
BlackBerry Applications using Microsoft Visual Studio and Database Handling.
SimDB Implementation & Browser IVOA InterOp 2008 Meeting, Theory Session 1. Baltimore, 26/10/2008 Laurent Bourgès This work makes use of EURO-VO software,
© 2006, National Research Council Canada © 2006, IBM Corporation Solving performance issues in OTS-based systems Erik Putrycz Software Engineering Group.
Preface IIntroduction Objectives I-2 Course Overview I-3 1Oracle Application Development Framework Objectives 1-2 J2EE Platform 1-3 Benefits of the J2EE.
EMEA Beat Schwegler Architect Microsoft EMEA HQ Ingo Rammer Principal Consultant thinktecture
ORM Basics Repository Pattern, Models, Entity Manager Ivan Yonkov Technical Trainer Software University
Integrating and Extending Workflow 8 AA301 Carl Sykes Ed Heaney.
CIS-NG CASREP Information System Next Generation Shawn Baugh Amy Ramirez Amy Lee Alex Sanin Sam Avanessians.
1 Copyright © 2008, Oracle. All rights reserved. Repository Basics.
Chapter 2 Build Your First Project A Step-by-Step Approach 2 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
Top 10 Entity Framework Features Every Developer Should Know
Introducing the Microsoft® .NET Framework
Introduction to Entity framework
DEPTT. OF COMP. SC & APPLICATIONS
Visual Basic 2010 How to Program
Introduction to .NET Florin Olariu
Introduction to Entity Framework
Lesson # 9 HP UCMDB 8.0 Essentials
ORACLE ADF ONLINE TRAINING COURSE
Best Practices and Architecture
Informatica PowerCenter Performance Tuning Tips
Entity Framework By: Casey Griffin.
ADO.NET Entity Framework
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 2 Database System Concepts and Architecture.
An Introduction to Entity Framework
Using JDeveloper.
Introduction of Week 11 Return assignment 9-1 Collect assignment 10-1
Rational Publishing Engine RQM Multi Level Report Tutorial
Plug-In Architecture Pattern
Presentation transcript:

Modeling, API, tools and best practices Viktor Zhivkov Telerik Software Academy Senior Software Developer, OpenAccess ORM

 Hello to OpenAccess  Features  Components  OpenAccess API  Working with LINQ  Bulk Operations  Code generation wizards 2

MS SQL SQL Compact Edition Oracle 9+LocalDbSQL Anywhere SQLiteMy SQL 5.0+MariaDb PostgreSQLSQL Azure VistaDBFirebirdADS 3

 Batch Operations over metadata  Code generation for Services  Runtime model modifications  Build-in validation framework .Net 3.5 Framework support  Pessimistic concurrency control  Level 2 caching  Advanced connection pooling 4

5

 Visual Designer – design surface where you can compose your data model  Toolbox – contains model building block – classes, associations and etc.  Model Explorer – view over the conceptual data model  Model Schema Explorer – view over the relational data model  Mapping details editor – tool used to map domain classes to relational tables 6

DEMO! 7

 Model settings dialog allows you to set up:  Your model, model names, database names,  Code generation options  Runtime configuration, logging, caching, connection pooling  Schema updates 8

 Pull changes made in the database into the existing conceptual model 9 DEMO

10 Push changes made to the conceptual model to the database in form of SQL DDL script DEMO

 Define your model using code-only mapping  Possible scenarios:  Code-first with lots of manual coding  Database-first with one-time code generation 11 DEMO

12 Metadata Container Class1 ClassNClass2 Runtime Configuration.CS Contains all required metadata that describes the model, like: -Domain Classes -Domain Methods

13 Metadata Container Class1 ClassNClass2 Runtime Configuration.CS Meta Persistent Type: Describes a domain class with all its properties, settings and mappings

14 Metadata Container Class1 ClassNClass2 Runtime Configuration.CS Configuration of the runtime, all switches available in Model Settings dialog

15 Metadata Container Class1 ClassNClass2 Runtime Configuration.CS Code file that defines the.Net class representing the model (derived from OpenAccessC ontext)

16 Metadata Container Class1 ClassNClass2 Runtime Configuration.CS Plain.Net class (POCO) that defines an entity (Domain Class)

 Entities bound to a data context need change tracking in order to be used in Create, Update, Delete operations (CUD operations)  Enhancer is the behind the scenes tool that does that for you with minimum interruption  Uses MSIL code weaving to inject the necessary code in your types  Required some changes in the default build process! 17

 Demo – see the original code and the enhanced one side by side 18 DEMO

 Create  1: new Entity();  2: context.Add();  3: context.SaveChanges();  Read – context.Entities.First(o => o.Id == id);  Update  1: entity.Name = entity.Name + “1”;  2: context.SaveChanges();  Delete  1: context.Remove(entity);  2: context.SaveChanges(); 19 DEMO

20 NewHollow Dirty Clean DeletedDetached NotManaged Remove () SaveChanges () Add () Load data SaveChanges () Detach () Attach () change

 Entity properties are loaded lazily by default!  Simple properties will have their data in- memory  Navigation properties will have the target entity in Hollow state 21 DEMO

 Load related objects eagerly  Different approaches  Fetch Strategy – applied to the OpenAccessContext and used for every delete that is included in the strategy  Include () – applied to a LINQ query  Optimizes the way data is loaded – can solve N+1 loading problems 22 DEMO

 Two levels of object caching:  Per context (Level 1 Cache) – in memory set of all loaded entities.  Per database (Level 2 Cache) – in memory set of all loaded entities across all context instances in the Application Domain  Also works in web farm scenarios using MSMQ synchronization  Prepared statement cache for SQL statements  Query cache for LINQ queries 23

 API for linking an entity to context or breaking the same link  One entity can be managed by only one context at a time  In order to persist an entity it should be detached  Attached entities are not suited to travel across application levels or service boundaries  Detached entities can track changes in their state 24

 Use short living context instances  L1 Cache can grow indefinitely  Entities can be included in wrong transaction  Best – use “using” block  Avoid FlushChanges  Opens transaction and keeps it active until SaveChanges() or ClearChanges() are called 25

 OpenAccess supports almost all of the features of LINQ to SQL and LINQ to EF  Some differences:  Queries that will be ineffective due client side execution of filters will throw exception rather than running as it does in EF  Generic property accessors using FieldValue () method  Support for 3 special names to access internal OA properties  Somewhat better DateTime and bitwise operations support 26 DEMO

 String-based LINQ API that mirrors parts of the original LINQ API  Useful with UI components that allow user- defined filtering, sorting and grouping  Used in OpenAccess to query artificial types  More on ScottGu’s blog ScottGu’s blogScottGu’s blog 27 DEMO

 Calling.ToList() too early or to hammer out errors  Using.Net specific or user-defined methods, types and properties  Missing FetchStrategy or Include()  Too broad FetchStrategy  Dispose the context before data is materialized 28 DEMO

 Use variables for filter criteria rather than in-place calculated values or literals and constants  Variables enable OpenAccess to cache  the compiled query and reuse it with different value  the query result  Avoid non-trivial projections. Any return type outside of the known entity types will cause the result not to be cached. When tempted to reduce the network traffic by reducing the number of returned columns consider how this can affect L1 and L2 caches and ideally test the performance with and without the projection for your whole scenario 29

 Use OpenAccessProfiler  Use openAccessContext.Log  Use IQueryable.ToString()  Use your favorite profiler provided by the database server vendor 30

 Update and Delete operations that operate on matching rows on the server side without loading data in the application’s memory  Matching rows are defined as the result of a LINQ query  Delete or update operations are performed efficiently on the database server  Normally a temporary table is used to how some intermediate data that is required for the operation. The tables is deleted when the transaction is complete  Behavior is similar to the normal delete and update of entities using OpenAccess context API 31

 Discount rental cars that are manufactured before 1990 by 20%: Context.Cars.Where(c => c.Year c.Year < 1990).UpdateAll(u => u.Set(c => c.Prize, c => c.Prize * 0,8)); Roughly equivalent in SQL to: update Cars c set(c.Prize = c.Prize * 0,8) where c.Year < DEMO

 Remove discontinued products from the database: Context.Products.Where(p => p.Discontinued).DeleteAll();  Roughly equivalent in SQL to: delete from Products p where p.Discontinued = 1 33 DEMO

 Each operation has its own transaction separate from the one in the OpenAccessContext  Bulk operations will invalidate any cached instances in the Level 2 Cache. Eviction is done by type and will affect usually a lot of objects.  A temporary table will be used. Appropriate permissions are required. If creation of temp table fails the required temporary data will be put in memory. 34

 Source queries and update descriptors should be 100% pushable to the database server  Setting reference navigation properties is possible but dangerous  Setting collection navigation properties is forbidden  Using symbolic names is allowed 35

 Can generated for you an entire service layer that exposes your data model in a few clicks  Supports generation of:  Plain WCF services with DTOs  Data Services  Web API  RESTful Collection Services  AtomPub 36 DEMO

 Can generate for you a Dynamic Data Web Application that gives you generic interface for CRUD operations over your data model 37 DEMO

 OpenAccess product   OpenAccess online documentation  started.aspx started.aspx started.aspx  OpenAccess Samples Kit  mples-kit.aspx mples-kit.aspx mples-kit.aspx  OpenAccess Forum  px px px 38

Questions?

1. Customize code generation Customize the OpenAccess Code Generation T4 templates so that all the generated classes inherit from a single non-persistent class. Then generate a model out of a Northwind database and demonstrate that with the generated OpenAccessContext and persistent classes you are able to retrieve and update data in a small console application (under the same solution but in a separate project). 40

2. Implement entity cloning using binary serialization Define a function that can clone single entity loaded from the database (for more fame – a graph of entities, starting with from one of the nodes). Test that all properties of the original instance have the same values as the ones on the cloned. 41

3. 3. Compare Bulk Delete with normal delete operation Insert entities in single table. Delete each row that has ID where ID mod 7 == 1 Once delete the entities using OpenAccessContext.Remove() method. Then delete the entities using DeleteAll() bulk operation. Both times track the SQL statements that are sent to the server. Both times measure the time required to complete the operation(s). For bonus points measure the memory consumption in addition to the time. Output the measurements in text file including timestamp and machine name 42

4. 4. Do code review of the code generated by Add OpenAccess Service wizard for Web API services Make critical code review (peer review) of the code generated by Add OpenAccess Service wizard for Web API services: Base controller, Concrete controllers, Base repository, Concrete repositories, Global asax routes definition Watch for bad practices in handling data-related task, bad design decisions, incorrect implementation of design patterns, code smells, bad code formatting, inefficient code and etc. List at least 3 issues with the generated code. 43

5. List 5 suggestions for improvements all over OpenAccess (issues described in Exercise 4 do not count!). Issues can be anything that made working with OpenAccess unpleasant – bugs, missing documentation, missing features, bad menu positioning, unexpected outcome, visual glitches… As with any bug/issue can you define the steps to reproduce it? 44

 "Web Design with HTML 5, CSS 3 and JavaScript" Telerik Academy  html5course.telerik.com html5course.telerik.com  Telerik Software Academy  academy.telerik.com academy.telerik.com  Telerik Facebook  facebook.com/TelerikAcademy facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com forums.academy.telerik.com