mysql entity framework
TRANSCRIPT
![Page 1: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/1.jpg)
Sun Microsystems
Reggie Burnett
Sun Microsystems
MySQL and the Entity Framework
![Page 2: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/2.jpg)
2
About MySQL
Leadership, innovation, market acceptance
• 14 years of development
• Acquired by Sun in Feb 2008
• 12 million product installations
• 85,000 downloads a day
• Performance, reliability, scalability
• Easy to use, administer, maintain
![Page 3: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/3.jpg)
3
Industry-Leading Customers
Powered by MySQL
Enterprise 2.0TelecommunicationsOn Demand, SaaS, Hosting
Web / Web 2.0 OEM / ISV's
![Page 4: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/4.jpg)
4
What will we cover today?
•A brief overview of the entity framework•This will not be an exhaustive review. Consider it 100 level.
•A peek under the hood at how Connector/Net works with the entity framework
•A demonstration using MySQL and the entity framework
•A quick look at some of the work arounds we use to work with MySQL
•How you can reach me?•www.twitter.com/rykr
•www.reggieburnett.com
![Page 5: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/5.jpg)
5
What is the Entity Framework?
You want to code against objects
that make sense for your application
but you want to work against any data source.
Entities
Released in July as part of Visual Studio 2008 SP1
![Page 6: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/6.jpg)
6
What can an entity represent?
It … almost anything!
SQL Data Services (SDS))
Google BigTable
![Page 7: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/7.jpg)
7
So why use the Entity Framework
•Normal ORM arguments here
•Change tracking, use of conceptual objects
•Application portability
instead of ADO.Net?
instead of LINQ to SQL?
•Entity Framework has a full provider model allowing future use of all types of data stores
•Entity Framework is much more flexible than L2S (inheritance and complex types)
![Page 8: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/8.jpg)
8
So why use the Entity Framework
•Fits better into the long term data platform vision from Microsoft
•Many future Microsoft tools will be leveraging the entity framework including tools such as SQL Reporting Services
•Allows common tools to be written (i.e. EF model browser in Visual Studio)
instead of Nhibernate (or ….)?
“So the differentiator is not that the EF supports more flexible
mapping than nHibernate or something like that, it's that the EF is
not just an ORM--it's the first step in a much larger vision of an
entity-aware data platform
-- Danny Simmons (Entity Framework team)
![Page 9: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/9.jpg)
9
Scotty, I need that mapping!
Conceptual(CSDL)
Storage(SSDL)
Mapping(MSL)
![Page 10: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/10.jpg)
10
The man behind the curtain
Entity Framework converts
query into queries against
physical store
…which are then converted
into command trees
… which are converted into SQL by Connector/Net
Connector/Net
INSERT …
![Page 11: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/11.jpg)
11
How the components stack up
MySQL
Connector/net (mysql.data.dll)
EF (mysql.data.entity.dll)
Your Application
We use a separate assembly for compatibility reasons
![Page 12: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/12.jpg)
12
Deployment on a local box
• Web deployment steps will work locally as well
• Installer will place components where they need to be– You must use the installer to get design time modeling
• If not using the installer…– Mysql.data.dll should be installed into GAC
– ..and registered in machine.config (installutil mysql.data.dll)
– Mysql.data.entity.dll should be installed into the GAC
– .. but does not need to be installed using installutil.
![Page 13: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/13.jpg)
13
Deployment to the web
• Same procedure as deploying mysql.data.dll to the web
• Create a reference from your project to mysql.data.dll and mysql.data.entity.dll
• Modify your web.config so the provider can be found:
<system.data>
<DbProviderFactories>
<clear/>
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,
Version=6.0.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /
</DbProviderFactories>
</system.data>
![Page 14: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/14.jpg)
14
A peek under the hood
Our provider is broken down into 3 areas.
1. Provider discovery
2. Manifest and store specification
3. SQL Generation
Provider Discovery
public sealed class MySqlClientFactory : DbProviderFactory, IServiceProvider
{
….
object IServiceProvider.GetService(Type serviceType)
{
// use reflection to return implementation of DbProviderServices
}
….
}
![Page 15: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/15.jpg)
15
Manifest and store discovery
ProviderManifest.xml Lists store specific data types and functions
<Type Name="time" PrimitiveTypeKind="Binary">
<FacetDescriptions><MaxLength DefaultValue="8" Constant="true" /><FixedLength DefaultValue="true" Constant="true" />
</FacetDescriptions></Type>
SchemaDefinition.ssdl Provides metadata queries and store definition
<EntitySet Name="STables" EntityType="Self.Table">
<DefiningQuery> SELECT … </DefiningQuery></EntitySet>
SchemaMapping.msl Provides a mapping between store objects and entity
framework objects<cs:EntityContainerMapping …>
<cs:EntitySetMapping Name="Tables" StoreEntitySet="STables" TypeName="Store.Table">
<cs:ScalarProperty Name="Id" ColumnName="Id" /></cs:EntitySetMapping>
![Page 16: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/16.jpg)
16
SQL Generation
• The elephant in the room
• Generates code for 4 different types of command trees– DbQueryCommandTree
– DbInsertCommandTree
– DbUpdateCommandTree
– DbDeleteCommandTree
• Can generate very long and complex SQL queries
• Generated SQL is being simplified in EF 4
![Page 17: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/17.jpg)
17
DEMOCreating a simple entity
framework application.
![Page 18: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/18.jpg)
18
Handling transactions
• TransactionScope is the easiest– Know the current limitations of this
• Object Services supports transaction scopes
• EntityConnection supports the BeginTransaction method– Returns an EntityTransaction object
– EntitySQL doesn’t support DML
• Remember to use transaction enabled storage engines like InnoDB
• DEMO – Inserting records
![Page 19: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/19.jpg)
19
Inheritance is a good thing
Table per type
• One to one mappings
• Can use a base entity
• Also table per concrete type
Table per hierarchy
• Uses single table
• Discriminator
• Top entity usually abstract
Two types are currently supported
![Page 20: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/20.jpg)
20
DEMOSimple Inheritance
![Page 21: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/21.jpg)
21
Unsigned Types and Stored Procs
• They are supported– Not directly supported by the entity framework
– We use the next larger integer type to represent an unsigned column
• Support for stored procedures– They are supported
– They work in the wizard
– MySQL 5.4 natively supports in/out and out parameters
• Best practice is to make your schema look as much like SQL Server as possible!
![Page 22: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/22.jpg)
22
Planned support
• We are committed to supporting Entity Framework, LinQ and other MS data-centric initiatives.
• Connector/Net 6.0 is out now!– Has support for Entity Framework 1.0
• Connector/Net 6.1 will not include native LinQ support– We had originally planned this but decided on other priorities
– Targeting 6.3 for some form of LinQ support
– Very interested in enabling LinQ on Mono!
![Page 23: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/23.jpg)
23
What We Suggest:
Learn about the most popular open-source database.> http://www.sun.com/mysql
Free trial offer — MySQL Enterprise.> http://www.sun.com/mysql/trial
Take advantage of the Enterprise Unlimited Server offer.> http://www.sun.com/mysql/unlimited
Try before you buy, then save.> http://www.sun.com/tryandbuy/specialdetail.jsp?spid=f17eb968-ce40-48c5-9f63-5deb8e339216
Save on a Sun server/storage bundle.> http://www.sun.com/specials/g/bundleofsun.xml?intcmp=1390
![Page 24: MySQL Entity Framework](https://reader033.vdocuments.site/reader033/viewer/2022050801/5514cc81497959161e8b48c7/html5/thumbnails/24.jpg)
24
Resources•Webinar replay (posted in three days)–http://mysql.com/news-and-events/on-demand-webinars/
•Upcoming Webinars>“For ISVs: What's New in MySQL Connector/NET 6.1”Tues 15 Sept, 10 am PT–http://mysql.com/news-and-events/web-seminars/display-407.html
>“For ISVs: Architecting Embedded Databases for High Performance Applications”, Wed 23 Sept, 10 am PT–http://mysql.com/news-and-events/web-seminars/display-405.html
•MySQL ISV / OEM Customers–http://mysql.com/customers/embedded/
•Chance to Win A $150 Amazon.com Gift Certificate!>Just complete MySQL's 3 minute survey on your product's development cycle–http://www.zoomerang.com/Survey/survey.zgi?p=WEB22957RJFHET
•Contact MySQL–http://mysql.com/about/contact/sales.html?s=oem