Steve Maier @YsFred4, @ThoughtsPrayers, @YsApps, @AppRochester http://strugglingthru.net/ [email protected]
Feb 07, 2016
Steve Maier@YsFred4, @ThoughtsPrayers, @YsApps, @AppRochesterhttp://strugglingthru.net/[email protected]
About mePrincipal Software Engineer at InfiMed, Inc (Varian Medical Systems)WPF, SQL Server 2005/2008, WCF, MFC, COM
Co-Founder of AppRochester Mobile device user group in Rochester, NYSpeaker in Buffalo, Rochester, Syracuse, and Boston
Hold 12 MS certificationsI have “drank the Microsoft koolaid” and enjoy it
Worked with, WPF, Silverlight, SQL Server (co-author), ASP.NET, MVC, Linq to SQL, EF, WCF, driver development, DirectX, XNA, and many more things.
11 apps in iOS store6 apps in Windows Phone store2 Android apps
OverviewAbout meEntity FrameworkCode FirstSQL CELocaldb
Entity FrameworkERM included in .NET 3.5 sp1Point EF to a database and have it generate classes
and relationships for youPrevious products like CodeSmith, nHibernate, etcDatabase First
EF 4.0 included with .NET 4.0fixed many bugs, added features like lazy loading
(Linq to SQL)EF 4.1 – online download, Package Manager
Adds Code FirstEF 4.3.1 current versionEF 5.0 beta
Adding migration -> versioning of databases
Database FirstCreate the database using scripts or SSMSPoint EF to an existing database
Generated an edmx file with the modelGreat for adding/converting existing
databases to a new ERM easilyUpdate the model from the database
Demo
Code FirstTakes the opposite approach
Start with the classes that you want to storeGenerate the databaseChanging the classes can regenerate the database
Migration in 4.3.1 and 5.0 is setup to handle updating the database better
Defaults to SQLExpress that is installed on the system4.3.1 will default to localdb if SQLExpress is not
installedAttributes or Fluent API
Demo
Code First Data Annotation (Attributes)KeyRequiredMaxLength / MinLengthNotMappedComplexTypeConcurrencyCheckTimeStampTable / ColumnDatabaseGeneratedInverseProperty / ForeignKeyErrorMessage – not really an annotation
SQL CESingle file, no server running – similar to AccessCE 3.5 and 4.0 are common versionsCan run on mobile devices (Windows CE 6,
Windows Phone 7.5)
localdbNew feature of SQL 2012Being installed with VS 2011 instead of SQL ExpressSame sqlserver.exe as SQLExpressNot launched as a service but launched as a child
process
SQL Ce vs LocalDbSQL CE LocalDb 2.5 MB download size
18 MB expanded on disk Single file Privately installed,
embedded, with the application
Non-admin installation option
Runs in-process with application
Database size support – 4G Code free, document safe,
file format Number of concurrent
connections - 256
32 MB download size > 160 MB on disk (TBD)
Multiple files Database size support – 10G Runs as process started by app Procedural T-SQL - Select
Case, If, features LINQ to SQL Distributed transactions Native XML, XQuery/XPath Stored procedures, views,
triggers Role-based security Number of concurrent
connections – unlimited but only local
Being bundled into VS 2011
• Transact-SQL - Common Query Features
• ADO.NET Entity Framework 4.1
Code First DEMOConverting a product with hardcoded values
to a database driven modelStarted developing with SQL CE for small
local databaseSimple table definitions
database