1 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Entity Framework with Oracle Alex Keh Principal Product Manager, Oracle

2 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Program Agenda

. Current Features . Upcoming Features . Using Sequences and Triggers . Data Type Mapping

3 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Current Features

4 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Oracle Support for LINQ and Entity Framework

. Entity Data Model Wizard and Designer . Query language interfaces – LINQ to Entities – Entity SQL – DML capabilities (/update/delete) . Entity Framework auto-generates DML statements for Oracle Database . Or use your own Oracle stored procedures for DML

5 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. D E M O N S T R A T I O N Entity Framework and LINQ

6 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Available ODP.NET-Specific Functionality

. All standard ADO.NET APIs supported using ODP.NET – Use EntityClient or ObjectContext . No ODP.NET-specific APIs available, except… – Settings available in the Registry or .NET config files including ODP.NET connection string attributes – E.g. FetchSize, SelfTuning, DllPath, Max Pool Size, HA Events, Load Balancing, etc.

7 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Function Imports

. Define .NET methods that map to stored procedures . Add Function Import dialog integration

8 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Return Implicit Result Sets

. Use REF CURSORs from stored procedures . Available to both EF and non-EF scenarios – EF: one result set per stored procedure – Non-EF: one or more result set per stored procedure . Return types – Complex – read-only – Entity – read and updatable . Define result set bind and metadata info in .NET config

9 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. D E M O N S T R A T I O N Function Import and Implicit Result Set

10 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Return stored procedure scalar values

. Bind directly to stored procedure . Only bind by name supported, not bind by position . No .NET config changes necessary

// C# ObjectParameter oparam = new ObjectParameter(“oparam", typeof(decimal));

11 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Model/Schema Generation

. Supported – Database-First – Model-First . Not supported (yet) – Code-First . Will be supported in an upcoming release

12 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Requirements

. .NET Framework 4 or higher – Supports EF 4 and higher – Supports DbContext APIs, but not Code First yet . Visual Studio 2010 or higher . ODAC – ODAC 11.2 Release 4 or higher – 32-bit and x64 – OUI and XCopy

13 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Recent Entity Framework Features

. ODAC 11.2 Release 5 – Entity Framework 5 certification

14 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Upcoming Features

15 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Oracle Database 12c for Entity Framework

. Boolean . SQL APPLY . Identity Column

16 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Boolean

. ODP.NET OracleBoolean data type – Use with PL/SQL Booleans only as a bind parameter . Use Booleans in Entity Framework Function Imports . Note: No SQL Boolean data type – Boolean cannot be a column type

17 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. SQL APPLY

. New APPLY syntax – Each row returned by a query's outer table expression invokes a table-valued function – APPLY semantics equivalent to Oracle Lateral View . EF query pipeline generates APPLY – Tends to occur in queries with correlated subqueries – APPLY syntax not generally available outside SQL Server – No straightforward work around if encountering APPLY

18 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Identity Column

. DB automatically generates auto-incrementing value as needed – Supports ANSI’s IDENTITY keyword . Benefit – Easier to set up auto incrementing values, such as for primary keys . Integrated with ODT and ODP.NET – E.g. ODT: Create table with auto-incrementing Identity column – E.g. ODP.NET: Add row without explicitly providing identity value

19 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Using Sequences and Triggers

20 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Sequences and Triggers

. Provides similar functionality to Identity column in Oracle DB 11g and earlier versions . How to set up – Create table with id column of type NUMBER – Create sequence to auto-increment numeric values – Create trigger to automatically insert the next number in sequence into id column

21 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Identity Columns in Entity Framework

. Method 1 – Use a stored procedure which inserts data and calls a sequence to auto-increment the “identity” column . Method 2 – Use trigger to auto-increment “identity” column – EF supports server-generated auto-incremented values . StoreGeneratedPattern in SSDL – For Oracle DB . Set StoreGeneratedPattern=“Identity” manually in SSDL

22 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. D E M O N S T R A T I O N Sequences and Triggers

23 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Data Type Mapping

24 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Customizing Oracle Number Mapping

. Use .NET config file for custom mapping Oracle NUMBER to .NET data types . Upper range defines the custom mapping

25 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Mapping Configuration File

26 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. D E M O N S T R A T I O N Custom Number Type Mapping

27 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Data Type Conversions Affecting Performance

. WHERE clause slow when comparing two values – Occurs when one side is Unicode and the other side isn’t, which leads to data conversion – Solution: Use EntityFunctions.AsNonUnicode() on the string variable columns that are not N types – Comparison on DB is between two non-Unicode values . POCO class attributes with Int* causes unnecessary casting – Solution: Use Decimal as attribute for number columns

28 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Conclusion and Q & A

29 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Upcoming .NET Sessions Thursday Oct 4 . Hands-on Lab: Building .NET Applications with Oracle – 12:45 PM - 3:15 PM, Marriott Marquis - Salon 10/11

30 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Additional Oracle .NET Resources

. OTN .NET Developer Center – http://otn.oracle.com/dotnet . Twitter – @OracleDOTNET . YouTube – http://www.youtube.com/user/OracleDOTNETTeam . For more questions – [email protected]

31 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Graphic Section Divider

32 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

33 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 34 Copyright © 2012, Oracle and/or its affiliates. All rights reserved. 35 Copyright © 2012, Oracle and/or its affiliates. All rights reserved.