Data in Windows 10 UWP Andy Wigley XML, JSON, SQLite or EF Core ?

Slides:



Advertisements
Similar presentations
The Use of Microsoft based Technologies for the benefit of the Community Prof. Avi Mendelson – Microsoft & Technion - Taub 643.
Advertisements

ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Access Web Apps – OK, Now What? EXTENDING ACCESS WEB APPS George Young Dawson Butte Software ACCESS DAY – OCTOBER DENVER,
Virtual techdays INDIA │ august 2010 Building ASP.NET applications using SQL Server Compact Chaitanya Solapurkar │ Partner Technical Consultant,
SQLite and the.NET Framework This PPT:
Migrating to EPiServer CMS 5 Johan Björnfot -
Introducing Xamarin 2.0 Introducing Xamarin 2.0 Michael Hutchinson
Software development. Chapter 5 – Data management.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
CONFIGURING WINDOWS SERVER MIS 424 Professor Sandvig.
September 2008 IT Software Development Guide.
Building Data Driven Applications Using WinRT and XAML Sergey Barskiy, Magenic Microsoft MVP – Data Platform Principal Consultant Level: Intermediate.
Session 1 - Introduction and Data Access Layer
Intro to Entity Framework By Shahed Chowdhuri Don’t drown in database design during WakeUpAndCode.com.
Windows Azure Tour Benjamin Day Benjamin Day Consulting, Inc.
© 2012 Autodesk Implementing Cloud-Based Productivity Solutions with the AutoCAD® ObjectARX® API Ravi Krishnaswamy Senior Software Architect.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Additional Topics. API Bindings Bindings Binding Native API’s Create Binding Project Drop Jar or.a Done.
While you are waiting, please install the Windows 10 phone emulators because the installation takes a while and we will be using them during the lab later.
Available via NuGet independently, major revisions infrequent and with minimal breaking changes, sole dependency for each MAML library. Contains HTTP,
1 CONFIDENTIAL.NET FEATURES OVERVIEW C# 6 ASP.NET 5 DNX PROJECT ASP.NET MVC 6 EF 7 A UGUST 4, 2015.
Presentation Name / 1 Visual C++ Builds and External Dependencies NAME.
Web Services Error Handling and Debugging. Agenda Simple SOAP faults Advanced SOAP faults SOAP headers and faults Error handling From a Service Perspective.
All information's of PLINQO in this Document, I got it from: So, you could visit the link above to research.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
Open project in Microsoft Visual Studio → build program in “Release” mode.
TODAY Android Studio Installation Getting started Creating your 1 st App Beginning to understanding Intents.
App Package Folder App data Folders Local Roaming Temp Removable Storage (SD Card) Cloud Credential Locker B/ground Transfer Publishers Shared Folder.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Entity Framework 7: What’s New? Ricardo Peres Technical Evangelist at Simplifydigital. Microsoft
Getting Started with Oracle Berkeley DB 11gR2 and ADO.NET
Entity Framework Database Connection with ASP Notes from started/getting-started-with-ef-using-mvc/creating-an-
CMPE 226 Database Systems April 19 Class Meeting Department of Computer Engineering San Jose State University Spring 2016 Instructor: Ron Mak
Introduction to MySQL  Working with MySQL and MySQL Workbench.
Exploring Networked Data and Data Stores Lesson 3.
Trimantra Software Solution Offshore Software Development Outsourcing Company Visit :
ASP.NET Core* 1.0 The Future of Web Apps Shahed Chowdhuri
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
Windows App Studio Windows App Studio is the tool that makes it fast and easy to build Windows 10 apps. It’s accessible from any device with a browser.
ASP.NET Core* Shahed Chowdhuri Sr. Technical WakeUpAndCode.com A Quick Overview of ASP.NET Core * aka ASP.NET 5 before.
Database Programming Basic JDBC Programming Concepts.
Xamarin Development with
Top 10 Entity Framework Features Every Developer Should Know
Introduction ITEC 420.
DevOps with ASP.NET Core and Entity Framework Core
Android Mobile Application Development
ASP.NET Programming with C# and SQL Server First Edition
Xamarin Studio Xamarin Curriculum for Xamarin Studio
Building Web Applications with Microsoft ASP
5/15/2018 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks.
 .NET CORE
Jon Galloway | Tech Evangelist Christopher Harrison | Head Geek
Did your feature got in, out or planned?
Customizing your device experience with assigned access
Microsoft Build /15/2018 6:28 AM © 2016 Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY,
An Introduction to Entity Framework
Programming SQLite on Windows Phone 8.1
Entity Framework Core.
Microsoft Connect /1/2018 2:36 AM
Entity Framework Core (EF Core)
Saranya Sriram Developer Evangelist | Microsoft
What’s new in ASP.NET Core and Entity Framework 2.2 (Preview 3)
Implementing Entity Framework with MVC Jump Start
C# - EF Core Intro IT College, Andres Käver, , Fall semester
SOAP web services in Microsoft Azure
TN19-TCI: Integration and API management using TIBCO Cloud™ Integration
Plug-In Architecture Pattern
DataBase Application .NET
ASP.NET Core 2.0 The Future of Web Apps Shahed Chowdhuri
Presentation transcript:

Data in Windows 10 UWP Andy Wigley XML, JSON, SQLite or EF Core ? Microsoft, Senior Developer Evangelist

Agenda Data Storage in UWP XML or JSON serialization SQLite Entity Framework Core 1.0

4/28/2017 Data Storage in UWP © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Locations where apps can access data 4/28/2017 Locations where apps can access data Cloud Credential Locker App App File Open/Save Picker APIs Picker Provider apps Publishers Shared Folder File System B/ground Transfer r/w r/w r/w r/w Temp App data Folders Pictures Videos Music - Direct access needs manifest capabilities Roaming App data Folders App Known Folders Local App data Folders r/w r/w r/w App Package Folder Removable Storage (SD Card) r/o © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Serializing POCO to files

Data serialization using Windows.Data.Json; .. public string Stringify() {     JsonArray jsonArray = new JsonArray();     foreach (School school in Education)     {         jsonArray.Add(school.ToJsonObject());     }     JsonObject jsonObject = new JsonObject();     jsonObject["id"] = JsonValue.CreateStringValue(Id);     // Treating a blank string as null     if (String.IsNullOrEmpty(Phone))         jsonObject["phone"] = JsonValue.CreateNullValue();     else         jsonObject["phone"] = JsonValue.CreateStringValue(Phone);     jsonObject["name"] = JsonValue.CreateStringValue(Name);     jsonObject["education"] = jsonArray;     return jsonObject.Stringify(); }

Data deserialization using Windows.Data.Json; .. JsonObject jsonObject = JsonObject.Parse(jsonString); Id = jsonObject.GetNamedString("id", ""); IJsonValue phoneJsonValue = jsonObject.GetNamedValue("phone"); if (phoneJsonValue.ValueType == JsonValueType.Null) {     Phone = null; } else {     Phone = phoneJsonValue.GetString(); } Name = jsonObject.GetNamedString("name", "");

SQLite

Why SQLite? Worlds’ most popular database Rich Features Reliable Widely used on iOS, Android, Python, Mono etc… Public Domain Small, Fast, Reliable Rich Features Embedded SQL in-process database engine Read/writes to ordinary disk files Supports multiple tables, indices, triggers and views Cross-platform – freely copy database files between 32-bit and 64-bit, or little endian and big endian Reliable Reputation for being very reliable Large automated test suite All transactions are ACID even if interrupted by system crashes or power failures

SQLite.org Documentation SQL Syntax C/C++ API Reference Source and tools download

SQLite now included in the UWP SDK Since Windows 10 v1511/SDK Build 10586, native code can reference SQLite directly from SDK To reference the SDK SQLite: include the following header in your project: #include <winsqlite/winsqlite3.h> Configure the project to link to winsqlite3.lib (right-click project > Properties > Linker > Input > add winsqlite3.lib to Additional Dependencies) Benefits: reduce the size of your application package rely on the platform to update the library periodically Using the SDK SQLite might also lead to performance advantages such as faster launch times

Managed code SQLite usage Rely on WinRT component wrappers, or C# p/invoke code On NuGet: SQLitePCL SQLiteWinRT SQLite-NET *doesn’t work currently!* These need sqlite3.dll to be referenced by your project Install SQLite for Universal App Platform Visual Studio Extension (.vsix), then reference from your project

Choice of .NET APIs …and others! SQLite-NET LINQ syntax Lightweight ORM SQLitePCL or SQLite-WinRT SQL statements Thin wrapper around the SQLite C API var db =  new SQLite.SQLiteAsyncConnection(App.DBPath); var _customer = await  (from c in db.Table<Customer>() where c.Id == customerId  select c).FirstOrDefaultAsync(); if (customer != null) {      var Id = _customer.Id;      var Name = _customer.Name;      } using (var conn = new SQLiteConnection("demo.db")) {      Customer customer = null; using (var statement = conn.Prepare( "SELECT Id, Name FROM Customer WHERE Id = ?")) { statement.Bind(1, customerId); if (SQLiteResult.DONE == statement.Step()) { customer = new Customer() { Id = (long)statement[0], Name = (string)statement[1] }; } …and others!

Create database *SQLite-NET* private void LoadDatabase() { {              // Set the path to the SQLite database              var DBPath = Path.Combine( Windows.Storage.ApplicationData.Current.LocalFolder.Path, "customers.sqlite");      // Initialize the database if necessary              using (var db = new SQLite.SQLiteConnection(DBPath,  SQLite.SQLiteOpenFlags.ReadWrite | SQLite.SQLiteOpenFlags.Create)) {                  // Create the tables if they don't exist                  db.CreateTable<Customer>();                  db.CreateTable<Project>();              }          }

Define entity objects *SQLite-NET* public class Customer {     [PrimaryKey, AutoIncrement]          public int Id { get; set; }          public string Name { get; set; }          public string City { get; set; }          public string Contact { get; set; }      }

Create database and tables SQLite-WinRT private void LoadDatabase()         {              // Specify database location    var db = new SQLiteWinRT.Database(ApplicationData.Current.LocalFolder, "sqlitedemo.db"); try  {          // Open a connection to the SQLite database – creates it if it does not exist    await db.OpenAsync();    string sql = @"CREATE TABLE IF NOT EXISTS Customer                     (Id      INTEGER PRIMARY KEY AUTOINCREMENT,             Name    VARCHAR( 140 ),                      City    VARCHAR( 140 ),                      Contact VARCHAR( 140 ) );";       await db.ExecuteStatementAsync(sql);    }         catch (Exception ex) {           var result = SQLiteWinRT.Database.GetSqliteErrorCode(ex.HResult);      throw new ApplicationException("Database create failed with error " + result);        }

Tip: SQLite-Net The SQLite-Net NuGet package does not work in UWP NuGet v3 does not allow a package to add additional content files to your project SQLite-Net actually consists of two C# source files , SQLite.cs and SQLiteAsync.cs that use p/invoke to call functions exported from sqlite3.dll – NuGet V2 used to add these files! Solution: Reference SQLite for Universal App Platform extension SDK (as normal) Copy SQLite.cs and SQLiteAsync.cs from a Windows 8.1 project

4/28/2017 Demo: SQLite © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

But those SQLite updates are so annoying! SQLite gets updated frequently Breaks your project references Coordinating team on specific version is a problem Can store SQLite SDK local to project

<SDKReference…> Copy SDK from C:\Program Files (x86)\Microsoft SDKs\UAP\v0.8.0.0\ExtensionSDKs to \libs folder in solution root

<SDKReference…> Edit csproj so that it looks in your \libs folder first for SDKs <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="…"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\..." /> <PropertyGroup> <SDKReferenceDirectoryRoot>$(SolutionDir)\libs;$(SDKReferenceDirectoryRoot) </SDKReferenceDirectoryRoot> </PropertyGroup> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Platform Condition=" '$(Platform)' == '' ">x86</Platform> <ProjectGuid>{12973612-88B5-4E3E-8805-B862CDEAAE1D}</ProjectGuid> … </Project>

Further Information on direct SQLite programming: A Developer's Guide to Windows 10: SQLite Local Database https://channel9.msdn.com/Series/A-Developers-Guide-to-Windows-10/10

Entity Framework Core 1.0

EF Core 1.0 Lightweight and extensible version of Entity Framework New Platforms Full .NET Framework ASP.NET Core Windows 10 UWP Mac Linux New Data Stores: Relational & non- relational Not a magic abstraction that hides underlying data store High level services that are useful on all/most stores Non-common concerns handled by provider extensions Example providers Relational (SQL Server, SQLite, Postgres, etc.) Azure Table Storage Redis In Memory (for testing) SQLite is currently the only supported provider for UWP

“Code First” data model public class BloggingContext : DbContext { public DbSet<Blog> Blogs { get; set; } public DbSet<Post> Posts { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) optionsBuilder.UseSqlite($"Filename=Blogging.db"); } protected override void OnModelCreating(ModelBuilder modelBuilder) // Make Blog.Url required modelBuilder.Entity<Blog>() .Property(b => b.Url) .IsRequired();

Define entities public class Blog { public int BlogId { get; set; } public string Url { get; set; } public List<Post> Posts { get; set; } } public class Post public int PostId { get; set; } public string Title { get; set; } public string Content { get; set; } public Blog Blog { get; set; }

4/28/2017 Demo: EF Core 1.0 © 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Ne zaboravite ispuniti upitnike. Čekaju vas vrijedne nagrade!