Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer

Similar presentations


Presentation on theme: "Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer"— Presentation transcript:

1 Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer http://nikolay.it

2  ADO.NET Entity Framework and LINQ  Code-first approach  Scaffolding  Model Binders  Data Validation  Kendo UI Grids 2

3 Object Relation Persistence Framework

4  Entity Framework (EF) is a standard ORM framework, part of.NET  Provides a run-time infrastructure for managing SQL-based database data as.NET objects  The relational database schema is mapped to an object model (classes and associations)  Visual Studio has built-in tools for generating Entity Framework SQL data mappings  Data mappings consist of C# classes and XML  A standard data manipulation API is provided 4

5  Entity Framework (EF) standard features:  Maps tables, views, stored procedures and functions as.NET objects  Provides LINQ-based data queries  Executed as SQL SELECTs on the database server  CRUD operations – Create/Read/Update/Delete  Create compiled queries – for executing the same parameterized query multiple times  Creating or deleting the database schema 5

6  When the application starts  EF translates into SQL the language-integrated queries in the object model  Sends them to the database for later execution 6

7  When the database returns the results  Entity Framework translates the database rows back to.NET objects  The database server is transparent, hidden behind the API  LINQ is executed over IQueryable  LINQ is executed over IQueryable  At compile time a query expression tree is emitted  At runtime SQL is generated and executed 7

8  The ObjectContext class  ObjectContext holds the database connection and the entity classes  Provides LINQ-based data access  Implements identity tracking, change tracking, and API for CRUD operations  Entity classes  Each database table is typically mapped to a single entity class (C# class) 8

9  Associations  An association is a primary key / foreign key based relationship between two entity classes  Allows navigation from one entity to another, e.g. Student.Courses  Concurrency control  Entity Framework uses optimistic concurrency control (no locking by default)  Provides automatic concurrency conflict detection and means for conflicts resolution 9

10  Comprehension Query Syntax  Extension Method Syntax 10

11 11 Entity Framework (+ LINQ) Entity Framework (+ LINQ) Schema First (database) Schema First (database) Model First (model designer) Model First (model designer) Code First (C# classes) Code First (C# classes) SQL Server (compact) SQL Server (compact) MySQL Azure (cloud) Oracle

12 What is Microsoft SQL Server?What is Microsoft SQL Server?  MS SQL Server is a Relational Database Management System (RDBMS) from Microsoft  The main language supported in SQL Server is Transact SQL (T-SQL), an extension of SQL  Powerful, trustworthy, easy-to-use DB server  The most recent version is SQL Server 2012  Works only on Windows systems  A free distribution exists (SQL Server Express)  http://www.microsoft.com/express/database/ http://www.microsoft.com/express/database/ 12

13 13 Design First Code First New Database Existing Database Model First Create.edmx model in designer Generate DB from.edmx Classes auto-generate from.edmx Database First Reverse engineer.edmx model Classes auto-generate from.edmx Code First Define classes & mapping in code Database auto-created at runtime Code First Define classes & mapping in code

14 14

15  Convention over configuration  Database naming  Primary Key  Relationships (navigation properties)  Data Annotations  Tells EF how to map the object model to the database model  Place annotations directly against the property in your class  System.ComponentModel.DataAnnotations 15

16  Key – Defines a Primary Key  Column – Defines DB column name  Table – Defines table name for a class  Required – Defines a Required DB field  NotMapped – Property not in DB mapping  MinLength() – Min length for a property  MaximumLength() – Max length for property  Range() – Defines a valid value range 16

17  Package Manager Console  Enable-Migrations (-ContextTypeName)  This creates a Migration folder in project  Creates Configuration.cs file  AutomaticMigrationsEnabled = true;  Seed method to populate some initial data  Creates __MigrationHistory system table in DB  Update-Database (-Verbose)  Pushes the migration changes to the DB  –script – create a SQL script of the changes 17

18  When the database doesn’t match conventions … 18

19 Please work, please work, please work…

20

21  TODO: Editor templates and view templates 21

22

23  To make east of handling HTTP post request  Help the populating the parameters in action methods 23 DefaultModelBinder

24 24

25

26  Attributes defined in System.ComponentModel.DataAnnotations  Covers common validation patterns  Required  StringLength  Regex  Range 26

27 27 AttributeDescription CompareChecks whether two specified properties in the model have the same value. CustomValidationChecks the value against the specified custom function. EnumDataTypeChecks whether the value can be matched to any of the values in the specified enumerated type. RangeChecks whether the value falls in the specified range. It defaults to numbers, but it can be configured to consider a range of dates, too. RegularExpressionChecks whether the value matches the specified expression. RemoteMakes an Ajax call to the server, and checks whether the value is acceptable. RequiredChecks whether a non-null value is assigned to the property. It can be configured to fail if an empty string is assigned. StringLengthChecks whether the string is longer than the specified value.

28  Custom attributes  Inherit ValidationAttribute 28

29  ModelState.IsValid – will give us information about the data validation success  ModelState.AddModelError – custom error 29

30  @Html.ValidationSummary – output errors  @Html.ValidationMessageFor(…) – outputs validation message for specified property 30 Text box with integrated client-side validation jQuery validation library required for unobtrusive JavaScript validation

31 31 AttributeDescription DisplayColumnSpecify the property of a model class for simple text display. HiddenInputRender value in a hidden input (when editing). UIHintSpecify the name of the template to use for rendering. DataTypeCommon templates (email, password, URL, currency) ReadOnlySpecify a read-only property (for model binding). DisplayFormatFormat strings and null display text ScaffoldColumnTurn off display and edit capabilities DisplayNameFriendly name for labels

32

33  TODO: Kendo Grids

34  TODO: Summary 34

35 форум програмиране, форум уеб дизайн курсове и уроци по програмиране, уеб дизайн – безплатно програмиране за деца – безплатни курсове и уроци безплатен SEO курс - оптимизация за търсачки уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop уроци по програмиране и уеб дизайн за ученици ASP.NET MVC курс – HTML, SQL, C#,.NET, ASP.NET MVC безплатен курс "Разработка на софтуер в cloud среда" BG Coder - онлайн състезателна система - online judge курсове и уроци по програмиране, книги – безплатно от Наков безплатен курс "Качествен програмен код" алго академия – състезателно програмиране, състезания ASP.NET курс - уеб програмиране, бази данни, C#,.NET, ASP.NET курсове и уроци по програмиране – Телерик академия курс мобилни приложения с iPhone, Android, WP7, PhoneGap free C# book, безплатна книга C#, книга Java, книга C# Николай Костов - блог за програмиране http://schoolacademy.telerik.com

36  “C# Programming @ Telerik Academy  csharpfundamentals.telerik.com csharpfundamentals.telerik.com  Telerik Software Academy  academy.telerik.com academy.telerik.com  Telerik Academy @ Facebook  facebook.com/TelerikAcademy facebook.com/TelerikAcademy  Telerik Software Academy Forums  forums.academy.telerik.com forums.academy.telerik.com


Download ppt "Nikolay Kostov Telerik Software Academy Senior Software Developer and Trainer"

Similar presentations


Ads by Google