Trends in Database Development: XML, .NET, WinFS

105
Trends in Database Development: XML, .NET, WinFS Alexander Vaschillo Microsoft

description

Trends in Database Development: XML, .NET, WinFS. Alexander Vaschillo Microsoft. SQL Server Stores Everything. Overall direction: Storing stuff whatever this stuff is Different data models Relational Hierarchical (XML) Object (Graphs) Files. Latest in SQL Server. XML - PowerPoint PPT Presentation

Transcript of Trends in Database Development: XML, .NET, WinFS

Page 1: Trends in Database Development: XML, .NET, WinFS

Trends in Database Development: XML, .NET, WinFSTrends in Database Development: XML, .NET, WinFS

Alexander VaschilloMicrosoftAlexander VaschilloMicrosoft

Page 2: Trends in Database Development: XML, .NET, WinFS

SQL Server Stores EverythingSQL Server Stores Everything

Overall direction: Storing stuff whatever this stuff isDifferent data models

RelationalHierarchical (XML)Object (Graphs)Files

Overall direction: Storing stuff whatever this stuff isDifferent data models

RelationalHierarchical (XML)Object (Graphs)Files

Page 3: Trends in Database Development: XML, .NET, WinFS

Latest in SQL ServerLatest in SQL Server

XMLMapping to relational (SQLXML)Native (XML Datatype)

ObjectsMapping to relational (ObjectSpaces)Native (CLR UDT)

.NET integrationServerClient

Using all of the aboveWinFS

XMLMapping to relational (SQLXML)Native (XML Datatype)

ObjectsMapping to relational (ObjectSpaces)Native (CLR UDT)

.NET integrationServerClient

Using all of the aboveWinFS

Page 4: Trends in Database Development: XML, .NET, WinFS

The Two WorldsThe Two Worlds

SQLSQLServerServer

RowSetRowSet

SQLSQL

Relational Relational worldworld

LanguageLanguage

Data Data storagestorage

Data Data outputoutput

XML XML worldworld

XMLXMLFilesFiles

XPathXPathXQueryXQuery

XML/XML/HTMLHTML

XMLXMLViewView

SQLXML SQLXML – –

Bringing Bringing worlds worlds

togethertogether

Page 5: Trends in Database Development: XML, .NET, WinFS

XSD Mapping ExampleXSD Mapping Example<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="Customer" msdata:relation="Customers"> <xsd:complexType> <xsd:sequence> <xsd:element name="Order" msdata:relation="Orders"> <xsd:annotation><xsd:appinfo> <msdata:relationship

parent="Customers" parent-key="CustomerID" child="Orders" child-key="CustomerID" /> </xsd:appinfo></xsd:annotation> <xsd:complexType>

<xsd:attribute name="OrderDate" type="xsd:dateTime"/> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="CustomerID" /> </xsd:complexType> </xsd:element></xsd:schema>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:mapping-schema"> <xsd:element name="Customer" msdata:relation="Customers"> <xsd:complexType> <xsd:sequence> <xsd:element name="Order" msdata:relation="Orders"> <xsd:annotation><xsd:appinfo> <msdata:relationship

parent="Customers" parent-key="CustomerID" child="Orders" child-key="CustomerID" /> </xsd:appinfo></xsd:annotation> <xsd:complexType>

<xsd:attribute name="OrderDate" type="xsd:dateTime"/> </xsd:complexType> </xsd:element> </xsd:sequence> <xsd:attribute name="CustomerID" /> </xsd:complexType> </xsd:element></xsd:schema>

Page 6: Trends in Database Development: XML, .NET, WinFS

Three WorldsThree Worlds

SQLSQLServerServer

RowSetRowSet

SQLSQL

Relational Relational worldworld

XML XML worldworld

XMLXMLFilesFiles

XPathXPathXQueryXQuery

XML/XML/HTMLHTML

MapMapMemoryMemory

ObjectObject

C#,C++,C#,C++,VBVB

Object Object worldworld

MapMap

Page 7: Trends in Database Development: XML, .NET, WinFS

New MappingNew MappingCustomer

Name

Product

PartNum

Customer

Name

Product

PartNum

PurchaseR

Data Model Graph

Data Model Graph

Mapping

Page 8: Trends in Database Development: XML, .NET, WinFS

XML data typeNative SQL typeUse for column, variable or parameter

CREATE TABLE docs (id INT PRIMARY KEY, xDoc XML NOT NULL)

Store un-typed or typed XML instancesWell-formed and validation checksOptional XML Schema enforcementXML instances stored as LOB (2GB)

Efficient binary representation

XML data typeNative SQL typeUse for column, variable or parameter

CREATE TABLE docs (id INT PRIMARY KEY, xDoc XML NOT NULL)

Store un-typed or typed XML instancesWell-formed and validation checksOptional XML Schema enforcementXML instances stored as LOB (2GB)

Efficient binary representation

Native XML StoreXML Data TypeNative XML StoreXML Data Type

Page 9: Trends in Database Development: XML, .NET, WinFS

Native XML StoreXML IndexNative XML StoreXML Index

Create XML index on XML columnCREATE XML INDEX idx_1 ON docs (xDoc)

Creates indexes on tags, values & pathsSpeeds up queries

Entire query is optimizedSame industry leading cost based optimizer

Indexes are used as available

Create XML index on XML columnCREATE XML INDEX idx_1 ON docs (xDoc)

Creates indexes on tags, values & pathsSpeeds up queries

Entire query is optimizedSame industry leading cost based optimizer

Indexes are used as available

Page 10: Trends in Database Development: XML, .NET, WinFS

XQuery: query XML documents and dataStandards-based: W3C

In document 123, return section heading of section 3 and laterSELECT id, xDoc::query('

for $s in /doc[@id = 123]//sec[@num >= 3]

return <topic>{data($s/heading)}</topic>')

FROM docs

XQuery: query XML documents and dataStandards-based: W3C

In document 123, return section heading of section 3 and laterSELECT id, xDoc::query('

for $s in /doc[@id = 123]//sec[@num >= 3]

return <topic>{data($s/heading)}</topic>')

FROM docs

XML QueryXML Query

Page 11: Trends in Database Development: XML, .NET, WinFS

XML View: Unification ModelXML View: Unification Model

SQL Server “Yukon” XML data typeUse XQuery

Relational columnsUse SQL

XML View hides representationUse XQuery against any data

SQL Server “Yukon” XML data typeUse XQuery

Relational columnsUse SQL

XML View hides representationUse XQuery against any data

CustomerID

ContactName

Street City XML data type

XML ViewXML ViewXQuery andXQuery and

UpdatesUpdatesCustomer Table

Page 12: Trends in Database Development: XML, .NET, WinFS

.NET Integration.NET Integration

Server side: SQLCLR.NET hosted inside the databaseWrite stored procedures in C#Use ADO programming model on the server the same way as on the client sideCreate UDTs

Client sideWeb ServicesDatasetObjectspaces

Server side: SQLCLR.NET hosted inside the databaseWrite stored procedures in C#Use ADO programming model on the server the same way as on the client sideCreate UDTs

Client sideWeb ServicesDatasetObjectspaces

Page 13: Trends in Database Development: XML, .NET, WinFS

SQLCLRSQLCLRComponent reuseMainstream development experienceFamiliar choice of programming languages and constructsLeverage existing libraries and componentsSeamless debugging and deploymentDeep integration with the engine

Component reuseMainstream development experienceFamiliar choice of programming languages and constructsLeverage existing libraries and componentsSeamless debugging and deploymentDeep integration with the engine

Page 14: Trends in Database Development: XML, .NET, WinFS

SQLCLR DevelopmentSQLCLR Development

VS .NET VS .NET ProjectProject

Assembly: “TaxLib.dll”

VB, C#, …VB, C#, … BuildBuild

SQL ServerSQL Server

SQL Data Definition: SQL Data Definition: create create assembly … assembly … create function … create function … create create procedure … procedure … create trigger … create trigger … create create type …type …

SQL Queries: SQL Queries: select select sum(sum(tax(sal,state)tax(sal,state) ) ) from Emp where county from Emp where county = ‘King’= ‘King’

Runtime hosted inside

SQL

Page 15: Trends in Database Development: XML, .NET, WinFS

Web Services OverviewWeb Services Overview

Natural client side programming modelTurn your existing Stored Procedures into web ServicesMessaging done according to SOAP 1.1 standardChoose how to model results

XMLObjectsDataset

Can run on database server or mid-tierIntegrated with Visual Studio

Natural client side programming modelTurn your existing Stored Procedures into web ServicesMessaging done according to SOAP 1.1 standardChoose how to model results

XMLObjectsDataset

Can run on database server or mid-tierIntegrated with Visual Studio

Page 16: Trends in Database Development: XML, .NET, WinFS

Easy Programming ModelEasy Programming Model

SQLXML generates WSDL automaticallyVisual Studio.NET recognizes a DatasetRetrieve results of a Stored Procedure and load into a Dataset in 1 line of code!

Dim Service As New MyHost.MyWebService()Dim retval As IntegerDataSet ds = Service.GetCustomer(Name)

SQLXML generates WSDL automaticallyVisual Studio.NET recognizes a DatasetRetrieve results of a Stored Procedure and load into a Dataset in 1 line of code!

Dim Service As New MyHost.MyWebService()Dim retval As IntegerDataSet ds = Service.GetCustomer(Name)

Page 17: Trends in Database Development: XML, .NET, WinFS

Web Services – Decoupled ArchitectureWeb Services – Decoupled Architecture

SQL ServerSQL ServerSQLXMLSQLXMLApplicationApplicationMethod callMethod call SQL querySQL query

RowsetRowsetXmlReaderXmlReader

ClientClient Mid-TierMid-Tier ServerServer

User User viewview

DBA DBA viewview

Page 18: Trends in Database Development: XML, .NET, WinFS

Universal StorageUniversal Storage

SQL server Abstracts data model from the userAbstracts data access programming model from the userAbstracts its existence from the user

Can it replace file system?

SQL server Abstracts data model from the userAbstracts data access programming model from the userAbstracts its existence from the user

Can it replace file system?

Page 19: Trends in Database Development: XML, .NET, WinFS

User FilesUser FilesUnstructured data

Not really unstructured – proprietary structure

Data broken into filesOne level of granularity (HTML, Powerpoint)Easy manipulation?

Proprietary formatsNeed particular application to interpret filesNo Sharing (Import/Export)No relationships

Duplication of DataCompatibility of data (Emails, Contacts,…)

Unstructured dataNot really unstructured – proprietary structure

Data broken into filesOne level of granularity (HTML, Powerpoint)Easy manipulation?

Proprietary formatsNeed particular application to interpret filesNo Sharing (Import/Export)No relationships

Duplication of DataCompatibility of data (Emails, Contacts,…)

Page 20: Trends in Database Development: XML, .NET, WinFS

WinFSWinFSDatabase

Reliability, Concurrency, Speed, query optimization

Understanding schemasUniform SearchNew APIs

SQLObjects

Old APIsWill be supported

Old files still workWant to enable richer integration – provide translations mechanisms

DatabaseReliability, Concurrency, Speed, query optimization

Understanding schemasUniform SearchNew APIs

SQLObjects

Old APIsWill be supported

Old files still workWant to enable richer integration – provide translations mechanisms

Page 21: Trends in Database Development: XML, .NET, WinFS

WinFS SchemasWinFS Schemas

Unification on some levelBase schemas shipped with Windows

Play by the rules – all applications will be enabled with your data

Use extensions for your proprietary data

Convenient programming modelShell supports librariesNavigation (relationships)Integration (Email body is a document)

Unification on some levelBase schemas shipped with Windows

Play by the rules – all applications will be enabled with your data

Use extensions for your proprietary data

Convenient programming modelShell supports librariesNavigation (relationships)Integration (Email body is a document)

Page 22: Trends in Database Development: XML, .NET, WinFS

Audio Videos Images Games. . .

Principals LocationsCalendar EventsCoreMessage (Email)

The Windows SchemasThe Windows Schemas

WinFSTypesMeta BaseFile SyncShellSubscriptions. . .

System Tasks Explorer Config NaturalUI Programs

Services SecurityHelp Device. . .

System

User DataDocumentsAnnotationsMedia NotesPerson Tasks

Infrastructure

Page 23: Trends in Database Development: XML, .NET, WinFS

WinFs Data ModelWinFs Data Model

Common data modelSimple but richCommon programming model for all applicationsUnified store - unified accessSubsume relational conceptsRich object abstraction for dataSemantic relationshipsAlign with CLR

Common data modelSimple but richCommon programming model for all applicationsUnified store - unified accessSubsume relational conceptsRich object abstraction for dataSemantic relationshipsAlign with CLR

Page 24: Trends in Database Development: XML, .NET, WinFS

Common Data ModelCommon Data Model

Map to CLR - frameworkMap to SQL – add some abstractionsExpress data in XMLCombine SQL 99, CLR, XSD, UML

Nested tablesRelationshipsScalar types

Provide mapping to other data models

Map to CLR - frameworkMap to SQL – add some abstractionsExpress data in XMLCombine SQL 99, CLR, XSD, UML

Nested tablesRelationshipsScalar types

Provide mapping to other data models

Page 25: Trends in Database Development: XML, .NET, WinFS

SQL 99 Data ModelSQL 99 Data Model

Too implementation specific – not a good application level abstractionTables, not types are first class

IdentityOperational semantics (copy, etc.)

Integrate SQL with Programming language rather than map from objects to DBNo high-level relationship support

Can use low-level concepts (foreign keys)

Too implementation specific – not a good application level abstractionTables, not types are first class

IdentityOperational semantics (copy, etc.)

Integrate SQL with Programming language rather than map from objects to DBNo high-level relationship support

Can use low-level concepts (foreign keys)

Page 26: Trends in Database Development: XML, .NET, WinFS

CLR Data ModelCLR Data Model

Framework on topConstrainEnhance with additional functionality

Not designed for persistenceReferences are not durableForeign keys can be persisted

No set–oriented query capabilitiesNo high-level relationship concepts

Can use collections to implement some

No support for BLOBs

Framework on topConstrainEnhance with additional functionality

Not designed for persistenceReferences are not durableForeign keys can be persisted

No set–oriented query capabilitiesNo high-level relationship concepts

Can use collections to implement some

No support for BLOBs

Page 27: Trends in Database Development: XML, .NET, WinFS

XML/XSD Data ModelXML/XSD Data Model

Use XML syntax, but not semanticsNo Relationships in XSD Data ModelToo many concepts not useful for us and hard to map to CLR and SQLDifferent set of scalar typesComplex mechanisms for type extension

Not compatible with CLR

Use XML syntax, but not semanticsNo Relationships in XSD Data ModelToo many concepts not useful for us and hard to map to CLR and SQLDifferent set of scalar typesComplex mechanisms for type extension

Not compatible with CLR

Page 28: Trends in Database Development: XML, .NET, WinFS

WinFS Data ModelWinFS Data Model

Items (Entities)Scalar typesInline TypesInheritanceExtensionsRelationships

Items (Entities)Scalar typesInline TypesInheritanceExtensionsRelationships

Page 29: Trends in Database Development: XML, .NET, WinFS

ItemsItems

Have identitySmallest referenceable unitHave Properties and Behaviors (methods)Can exist independently, can be copied, etc.Person, Message, Document, Audio,...

<EntityType Name="Person"> <Property Name="Name" Type="WinFS.String"/> <Property Name="Age" Type="WinFS.Int32"

Default="1"/> <Property Name="Picture" Type="WinFS.Binary"/> <Property Name="Addresses"

Type="Array(Address)"/></EntityType>

Have identitySmallest referenceable unitHave Properties and Behaviors (methods)Can exist independently, can be copied, etc.Person, Message, Document, Audio,...

<EntityType Name="Person"> <Property Name="Name" Type="WinFS.String"/> <Property Name="Age" Type="WinFS.Int32"

Default="1"/> <Property Name="Picture" Type="WinFS.Binary"/> <Property Name="Addresses"

Type="Array(Address)"/></EntityType>

Page 30: Trends in Database Development: XML, .NET, WinFS

Scalar TypesScalar Types

Used for properties on an Item (Relatonship)Carefully chosen subset of SQL and CLR typesString, Boolean, Binary, Byte, Int16, Int32, Int64, Single, Double, Decimal, DateTime, Guid, XML, Stream.Enumeration

<Enumeration Name="Gender" > <EnumerationMember Name="Male" /> <EnumerationMember Name="Female" /></Enumeration>

Arrays and Sets

Used for properties on an Item (Relatonship)Carefully chosen subset of SQL and CLR typesString, Boolean, Binary, Byte, Int16, Int32, Int64, Single, Double, Decimal, DateTime, Guid, XML, Stream.Enumeration

<Enumeration Name="Gender" > <EnumerationMember Name="Male" /> <EnumerationMember Name="Female" /></Enumeration>

Arrays and Sets

Page 31: Trends in Database Development: XML, .NET, WinFS

Inline typeInline type

A structure without identityNot referenceableHas to be contained in an Entity (or Relationship)Example: Address

<InlineType Name="Address"> <Property Name="Street" Type="String"

Nullable="false"/> <Property Name="City" Type="String"

Nullable="false"/> ...</InlineType>

A structure without identityNot referenceableHas to be contained in an Entity (or Relationship)Example: Address

<InlineType Name="Address"> <Property Name="Street" Type="String"

Nullable="false"/> <Property Name="City" Type="String"

Nullable="false"/> ...</InlineType>

Page 32: Trends in Database Development: XML, .NET, WinFS

InheritanceInheritance

Single inheritance (Items, Inline types)Substitutability

<Type Name="Name" > <Property Name="FirstName" Type="WinFS.String"

/> <Property Name="LastName" Type="WinFS.String"

/></Type><Type Name="NameWithMiddleInitial"

BaseType="Name" > <Property Name="MiddleInitial"

Type=“WinFS.String" /></Type><Type Name="Person"

BaseType="System.Storage.Item" > <Property Name=" PersonalName"

Type="Array(Name)" /></Type>

Single inheritance (Items, Inline types)Substitutability

<Type Name="Name" > <Property Name="FirstName" Type="WinFS.String"

/> <Property Name="LastName" Type="WinFS.String"

/></Type><Type Name="NameWithMiddleInitial"

BaseType="Name" > <Property Name="MiddleInitial"

Type=“WinFS.String" /></Type><Type Name="Person"

BaseType="System.Storage.Item" > <Property Name=" PersonalName"

Type="Array(Name)" /></Type>

Page 33: Trends in Database Development: XML, .NET, WinFS

Inheritance HierarchyInheritance Hierarchy

Item

DocumentContact Message

Person Organization Email Fax Voice

Page 34: Trends in Database Development: XML, .NET, WinFS

ExtensionsExtensions

Non-invasively adds more structures to an existing ItemMultiple extensions can be added independentlyMust be attached to an Item and live with it

<EntityExtensionType Name=”MSNData” ExtendsType=”PersonItem” >

<Property Name="Passport" Type="PassportData" />

<Property Name="MSNId" Type="Guid" /></EntityExtentionType>

Non-invasively adds more structures to an existing ItemMultiple extensions can be added independentlyMust be attached to an Item and live with it

<EntityExtensionType Name=”MSNData” ExtendsType=”PersonItem” >

<Property Name="Passport" Type="PassportData" />

<Property Name="MSNId" Type="Guid" /></EntityExtentionType>

Page 35: Trends in Database Development: XML, .NET, WinFS

RelationshipsRelationships

Document-Author, Message-Participant, Album-RecordAssociation and CompositionRelate two ItemsMay have propertiesSupport cardinalities (1:1, m:1, 1:m, m:m)May control lifetimeBased on common values or identity

Document-Author, Message-Participant, Album-RecordAssociation and CompositionRelate two ItemsMay have propertiesSupport cardinalities (1:1, m:1, 1:m, m:m)May control lifetimeBased on common values or identity

Page 36: Trends in Database Development: XML, .NET, WinFS

Relationship ExampleRelationship Example

<EntityType Name="Customer" ...> ...</EntityType>

<EntityType Name="Order" ...> <Property Name="CustRef"

Type="Ref(Customer)"/> ...</EntityType>

<Association Name="OrderCustomer" > <End Role="OrderRole" Type="Order"

Multiplicity="*" /> <End Role="CustomerRole" Type="Customer"

OnDelete="Cascade” Multiplicity="1" /> <Reference FromRole=”OrderRole”

ToRole=”CustomerRole” Property=”CustRef”/></Association>

<EntityType Name="Customer" ...> ...</EntityType>

<EntityType Name="Order" ...> <Property Name="CustRef"

Type="Ref(Customer)"/> ...</EntityType>

<Association Name="OrderCustomer" > <End Role="OrderRole" Type="Order"

Multiplicity="*" /> <End Role="CustomerRole" Type="Customer"

OnDelete="Cascade” Multiplicity="1" /> <Reference FromRole=”OrderRole”

ToRole=”CustomerRole” Property=”CustRef”/></Association>

Page 37: Trends in Database Development: XML, .NET, WinFS

Relationship ExampleRelationship Example

<Association Name="DocumentAuthor" > <End Role="DocumentRole" Type="Document"

Multiplicity="*" /> <End Role="ContactRole" Type="Contact"

Multiplicity="1"/> <Condition> DocumentRole.Author = ContactRole.Name </Condition ></Association>

<Association Name="DocumentAuthor" > <End Role="DocumentRole" Type="Document"

Multiplicity="*" /> <End Role="ContactRole" Type="Contact"

Multiplicity="1"/> <Condition> DocumentRole.Author = ContactRole.Name </Condition ></Association>

Page 38: Trends in Database Development: XML, .NET, WinFS

Data Model MappingData Model Mapping

A WinFS schema is mapped to a SQL schema Types are mapped to CRL classes in the storage (UDT), and CLR API classesClasses are automatically created based on type definitionViews are generated for each typeRelationships: UDT vs. metadataSchema becomes a namespace in the API

A WinFS schema is mapped to a SQL schema Types are mapped to CRL classes in the storage (UDT), and CLR API classesClasses are automatically created based on type definitionViews are generated for each typeRelationships: UDT vs. metadataSchema becomes a namespace in the API

Page 39: Trends in Database Development: XML, .NET, WinFS

WinFS APIWinFS API

Natural programming modelLanguage integrationCollections vs. SQL QueriesDatabase operations are hidden from a developer

Natural programming modelLanguage integrationCollections vs. SQL QueriesDatabase operations are hidden from a developer

Page 40: Trends in Database Development: XML, .NET, WinFS

Querying WinFSQuerying WinFS

StorageContext sc = new StorageContext();

StorageSearcher<PersonItem> searcher =sc.Items.FilterByType<PersonItem>().

Filter(“Exists(Names[LastName=’Smith’]”);

PersonItem p1 = searcher.GetFirst();or

foreach (PersonItem p in searcher){ ...

}

StorageContext sc = new StorageContext();

StorageSearcher<PersonItem> searcher =sc.Items.FilterByType<PersonItem>().

Filter(“Exists(Names[LastName=’Smith’]”);

PersonItem p1 = searcher.GetFirst();or

foreach (PersonItem p in searcher){ ...

}

Page 41: Trends in Database Development: XML, .NET, WinFS

Query CompositionQuery Composition

StorageSearcher<MessageItem> messages =sc.Items.FilterByType<MessageItem>().

Filter("Subject LIKE '%Academic Days%'");

StorageSearcher<StorageRecord> myMessages= messages.Project("Subject, Size ").

Sort(“Size desc”);

foreach( StorageRecord m in myMessages){ string s = m[“Subject”]; int size = m[“Size”];}

StorageSearcher<MessageItem> messages =sc.Items.FilterByType<MessageItem>().

Filter("Subject LIKE '%Academic Days%'");

StorageSearcher<StorageRecord> myMessages= messages.Project("Subject, Size ").

Sort(“Size desc”);

foreach( StorageRecord m in myMessages){ string s = m[“Subject”]; int size = m[“Size”];}

Page 42: Trends in Database Development: XML, .NET, WinFS

Item CreationItem Creation

Item root = sc.GetRootItem();

PersonItem person = new PersonItem();person.DateOfBirth = “11/01/1960";

FullName fullName = new FullName();fullName.FirstName = “John”;fullName.LastName = “Smith”;person.Names.Add(fullName);

root.Children.Add(person);sc.SaveChanges();

Item root = sc.GetRootItem();

PersonItem person = new PersonItem();person.DateOfBirth = “11/01/1960";

FullName fullName = new FullName();fullName.FirstName = “John”;fullName.LastName = “Smith”;person.Names.Add(fullName);

root.Children.Add(person);sc.SaveChanges();

Page 43: Trends in Database Development: XML, .NET, WinFS

Relationship NavigationRelationship Navigation

StorageSearcher<OrganizationItem> organizations =sc.Items.WithType<OrganizationItem>().

Filter("Keywords[Value=‘Financial']");

StorageSearcher<PersonItem> employees = EmploymentRelation.GetEmployees(organizations);

StorageSearcher<DocumentItem> documents = DocumentAuthorRelation.GetDocuments(employees);

foreach( DocumentItem document in documents){ ...}

StorageSearcher<OrganizationItem> organizations =sc.Items.WithType<OrganizationItem>().

Filter("Keywords[Value=‘Financial']");

StorageSearcher<PersonItem> employees = EmploymentRelation.GetEmployees(organizations);

StorageSearcher<DocumentItem> documents = DocumentAuthorRelation.GetDocuments(employees);

foreach( DocumentItem document in documents){ ...}

Page 44: Trends in Database Development: XML, .NET, WinFS

NotificationsNotificationsPersonItem person =

sc.Items.FilterByType<PersonItem>().

Filter(“Exists(Names[LastName=’Smith’]”).GetFirst();

StoreWatcherOptions Opts=new StoreWatcherOptions();

Opts.NotifyModified = true;

StoreWatcher w = person.GetWatcher( Opts );w.StoreObjectChanged += new

StoreEventHandler( MyHandler );

void MyHandler( Object sender, StoreEventArgs e ){

…}

PersonItem person = sc.Items.FilterByType<PersonItem>().

Filter(“Exists(Names[LastName=’Smith’]”).GetFirst();

StoreWatcherOptions Opts=new StoreWatcherOptions();

Opts.NotifyModified = true;

StoreWatcher w = person.GetWatcher( Opts );w.StoreObjectChanged += new

StoreEventHandler( MyHandler );

void MyHandler( Object sender, StoreEventArgs e ){

…}

Page 45: Trends in Database Development: XML, .NET, WinFS

Creating API for a SchemaCreating API for a SchemaCreate WinFS schema in XML formatSchema compiler generates API assemblyYou can add your own “helper” membersThe assemblies are installed into a WinFS store

WinFS types are registered as UDTs

Views and other database objects are created

Create WinFS schema in XML formatSchema compiler generates API assemblyYou can add your own “helper” membersThe assemblies are installed into a WinFS store

WinFS types are registered as UDTs

Views and other database objects are created

WinFSSchema

CLR Complier

Code for Helper Members

WinFSSchemaCompiler Code for

Standard API APIClasses

CLR Complier

SchemaAssembliesC# code

for UDTs

Page 46: Trends in Database Development: XML, .NET, WinFS

Body- Preference

WinFS Message Schema (Example)WinFS Message Schema (Example)

Message-Subject-Time sent-Type-Status

Contact-Name-Address-Email-Photo

Document-Title-Size-Type-

Document-Title-Size-Type-

Account-Name-Quota-Type-Server

Participant-DisplayName-Type-Address

Component

Page 47: Trends in Database Development: XML, .NET, WinFS

My Favorite QueryMy Favorite Query

What do I know about “John Smith”Documents by/about himEmails from himHis addressPhone calls from himAnnotations he added to my papersMeetings with him

What do I know about “John Smith”Documents by/about himEmails from himHis addressPhone calls from himAnnotations he added to my papersMeetings with him

Page 48: Trends in Database Development: XML, .NET, WinFS
Page 49: Trends in Database Development: XML, .NET, WinFS

Choice of XML TechnologyChoice of XML TechnologyNative XML Technology

Very simple way of storing XML dataXML schema is optionalDocument order is importantQuery and modify XML dataIndex XML data

XML View TechnologyXML-centric programming model over tablesSchema for XML data requiredOrder not importantBulk load XML data; decompose into tables

Native XML TechnologyVery simple way of storing XML dataXML schema is optionalDocument order is importantQuery and modify XML dataIndex XML data

XML View TechnologyXML-centric programming model over tablesSchema for XML data requiredOrder not importantBulk load XML data; decompose into tables

Page 50: Trends in Database Development: XML, .NET, WinFS

File Migration to WinFSFile Migration to WinFS

File promotion / demotionWrite conversion routines for common file types (gif, eml, doc, pdf,...)Works for non-WinFS stores (removable media, etc.)WinFS apps use one API to write pure WinFS and file-backed itemsAllows interop between legacy and new applications

File promotion / demotionWrite conversion routines for common file types (gif, eml, doc, pdf,...)Works for non-WinFS stores (removable media, etc.)WinFS apps use one API to write pure WinFS and file-backed itemsAllows interop between legacy and new applications

Page 51: Trends in Database Development: XML, .NET, WinFS

Database developmentDatabase development

Relational model is working wellBenchmarksSecurityEnhancements

New modelsHierarchical (XML)Object

Ease of useNew uses

WinFS

Relational model is working wellBenchmarksSecurityEnhancements

New modelsHierarchical (XML)Object

Ease of useNew uses

WinFS

Page 52: Trends in Database Development: XML, .NET, WinFS

Why new data modelsWhy new data models

Flat relational result is good to print reportsHierarchical result is ideal for Web PagesObject data model is for programming against

DatasetObjectspacesWeb Services

Flat relational result is good to print reportsHierarchical result is ideal for Web PagesObject data model is for programming against

DatasetObjectspacesWeb Services

Page 53: Trends in Database Development: XML, .NET, WinFS

Why XML?Why XML?

Presentation formatTransport formatPlatform independentText-based formatSchema with dataInternational standard not owned by any one company

Presentation formatTransport formatPlatform independentText-based formatSchema with dataInternational standard not owned by any one company

Page 54: Trends in Database Development: XML, .NET, WinFS

HTTP Access Via URLHTTP Access Via URLURL Queryhttp://server/vroot?sql=select+*+from+Customers+FOR+XML+Auto&root=root

XML Viewhttp://server/vroot/schema.xsd

/Customer[@ID='ALFKI']?params

Templatehttp://server/vroot/template.xml?params

URL Queryhttp://server/vroot?sql=select+*+from+Customers+FOR+XML+Auto&root=root

XML Viewhttp://server/vroot/schema.xsd

/Customer[@ID='ALFKI']?params

Templatehttp://server/vroot/template.xml?params

Page 55: Trends in Database Development: XML, .NET, WinFS

Loosely Coupled SystemsLoosely Coupled Systems

Scalable. Many to Many.Changes in Implementation do not break each other

Scalable. Many to Many.Changes in Implementation do not break each other

AppAppLogicLogic DataDataMappingMapping MappingMapping

Application SystemApplication System Data SystemData System

ObjectObject(XML)(XML)

Move data in a standardized format (XML)Move data in a standardized format (XML)

Page 56: Trends in Database Development: XML, .NET, WinFS

SQLXML From 10,000 FeetSQLXML From 10,000 FeetProvides a rich XML view of relational dataSemi-structured, hierarchical view of flat relational dataTwo-way view: query and updateMultiple access mechanisms (HTTP, ADO, ADO.NET, SOAP)Middle tier and Server sideXML: extensible, platform independent format for your data

Provides a rich XML view of relational dataSemi-structured, hierarchical view of flat relational dataTwo-way view: query and updateMultiple access mechanisms (HTTP, ADO, ADO.NET, SOAP)Middle tier and Server sideXML: extensible, platform independent format for your data

Page 57: Trends in Database Development: XML, .NET, WinFS

XML ViewsXML Views

Map between relational data and XMLDeclarativeNoninvasive

No changes to legacy data sourcesNo control over DB Server required

XML View is an XML SchemaXSD for SQLXML 2.0 and 3.0MSD for Yukon

Map between relational data and XMLDeclarativeNoninvasive

No changes to legacy data sourcesNo control over DB Server required

XML View is an XML SchemaXSD for SQLXML 2.0 and 3.0MSD for Yukon

Page 58: Trends in Database Development: XML, .NET, WinFS

XML Schema SupportXML Schema Support

XML Schema (W3C standard)Rich mechanism for type definitions and validation constraintsCan be used to constrain XML documents

Benefits of typed data Guarantees shape of dataAllows storage and query optimizations

XML type systemStore XML schemas in system meta-data

XML Schema (W3C standard)Rich mechanism for type definitions and validation constraintsCan be used to constrain XML documents

Benefits of typed data Guarantees shape of dataAllows storage and query optimizations

XML type systemStore XML schemas in system meta-data

Page 59: Trends in Database Development: XML, .NET, WinFS

Insert, update, and delete XQuery extensionsXML sub-tree modification:

Add or delete XML sub-treesUpdate values

Add a new section after section 1:UPDATE docs SET xDoc::modify('insert<section num=''2''> <heading>Background</heading> </section>after /doc/section[@num=1]')

Insert, update, and delete XQuery extensionsXML sub-tree modification:

Add or delete XML sub-treesUpdate values

Add a new section after section 1:UPDATE docs SET xDoc::modify('insert<section num=''2''> <heading>Background</heading> </section>after /doc/section[@num=1]')

XML Data ModificationXML Data Modification

Page 60: Trends in Database Development: XML, .NET, WinFS

Design GuidelinesDesign GuidelinesT-SQL is best suited for data access

Relational programming modelStatic compilation modelOptimized for data access

SLQCLR is for procedural programming and computation

IL compiled to x86 code at runtime, easily outperforms interpreted T-SQLCompute-intensive business logic encapsulated as functions

Moving computation to where the data isData shipping cost goes awayServer CPU now used for user processing

T-SQL is best suited for data accessRelational programming modelStatic compilation modelOptimized for data access

SLQCLR is for procedural programming and computation

IL compiled to x86 code at runtime, easily outperforms interpreted T-SQLCompute-intensive business logic encapsulated as functions

Moving computation to where the data isData shipping cost goes awayServer CPU now used for user processing

Page 61: Trends in Database Development: XML, .NET, WinFS

SOAP And Web ServicesSOAP And Web Services

WSDL file describing each template and stored proc exposedTool to choose which templates and stored procedures to expose

WSDL file describing each template and stored proc exposedTool to choose which templates and stored procedures to expose

SQLSQLServerServer

IIS/ISAPIIIS/ISAPI

MessageMessageSPSP

TemplateTemplate

ClientClient SOAPSOAP

MessageMessage

WSDLWSDL

Page 62: Trends in Database Development: XML, .NET, WinFS

Levels of AbstractionLevels of Abstraction

Abstract the data source – XML ViewAbstract the data access – HTTP queriesAbstract programming model – SQL Server Web Services

Abstract the data source – XML ViewAbstract the data access – HTTP queriesAbstract programming model – SQL Server Web Services

Page 63: Trends in Database Development: XML, .NET, WinFS

Data Model TransparencyData Model Transparency

XML Views – treat your relational data as if it was XML FileUse XML Query LanguagesPerform XML UpdatesNo need to be a DBA, learn SQL, or database programming APIs/logic

XML Views – treat your relational data as if it was XML FileUse XML Query LanguagesPerform XML UpdatesNo need to be a DBA, learn SQL, or database programming APIs/logic

Page 64: Trends in Database Development: XML, .NET, WinFS

Data Access TransparencyData Access Transparency

Access your data from any platformHTTP queries - platform independent protocolXML results – standard representation of dataUse SQL or XPath to query

Access your data from any platformHTTP queries - platform independent protocolXML results – standard representation of dataUse SQL or XPath to query

Page 65: Trends in Database Development: XML, .NET, WinFS

Programming Model TransparencyProgramming Model Transparency

Web servicesUse from any platformCall methods – get XML data returned

SQL Server stored procedure or XML Template is calledResults are transformed into XML form as needed

SQLCLR: programming model is the same on the server and on the client

Loosely coupled architecture

Web servicesUse from any platformCall methods – get XML data returned

SQL Server stored procedure or XML Template is calledResults are transformed into XML form as needed

SQLCLR: programming model is the same on the server and on the client

Loosely coupled architecture

Page 66: Trends in Database Development: XML, .NET, WinFS

WinFS: Structured Data StorageWinFS: Structured Data Storage

Files vs. DatabasesNTFS

Part of Operating SystemBackupWin32 APIsSimple

DatabaseOptimized for queryingReliabilitySecurityTransactions, multi-user, concurrency

Files vs. DatabasesNTFS

Part of Operating SystemBackupWin32 APIsSimple

DatabaseOptimized for queryingReliabilitySecurityTransactions, multi-user, concurrency

Page 67: Trends in Database Development: XML, .NET, WinFS

WinFSWinFS

System FilesExeDllSwap…

User FilesDocumentsPicturesMessages…

System FilesExeDllSwap…

User FilesDocumentsPicturesMessages…

Page 68: Trends in Database Development: XML, .NET, WinFS

WinFS Data ModelWinFS Data ModelItems

Person, Document, Message, Meeting, etc.

RelationshipsAuthor, Attachment, Meeting participant

Nested typesAddress

ExtensionsProprietary dataMultityping

Inheritance

ItemsPerson, Document, Message, Meeting, etc.

RelationshipsAuthor, Attachment, Meeting participant

Nested typesAddress

ExtensionsProprietary dataMultityping

Inheritance

Page 69: Trends in Database Development: XML, .NET, WinFS

WinFS API ExampleWinFS API Example

using (ItemContext ic = new ItemContext())

{ic.Open();

Contact c = (Contact) ic.FindItem( typeof(System.Storage.Contact.Person),

“DisplayName == ‘Bob Smith’”);

c.DisplayName = ‘Robert Smith’;c.BirthDate = ‘01/04/1982’;ic.Update();

}

using (ItemContext ic = new ItemContext())

{ic.Open();

Contact c = (Contact) ic.FindItem( typeof(System.Storage.Contact.Person),

“DisplayName == ‘Bob Smith’”);

c.DisplayName = ‘Robert Smith’;c.BirthDate = ‘01/04/1982’;ic.Update();

}

Page 70: Trends in Database Development: XML, .NET, WinFS

WinFS foldersWinFS folders

Every Item must be in at least one folderItem organizationLifetime managementOne file can be in multiple folders (reference counting)User can add custom fields to folders

Every Item must be in at least one folderItem organizationLifetime managementOne file can be in multiple folders (reference counting)User can add custom fields to folders

Page 71: Trends in Database Development: XML, .NET, WinFS

Database IntegrationDatabase Integration

XMLObject storageProgramming modelDevelopment environmentWebFile systemApplications

XMLObject storageProgramming modelDevelopment environmentWebFile systemApplications

Page 72: Trends in Database Development: XML, .NET, WinFS

ReportsReports

Example of table report and HTML report. Sales by quarter.Example of table report and HTML report. Sales by quarter.

Page 73: Trends in Database Development: XML, .NET, WinFS

WinFS Data model exampleWinFS Data model example

List of schema inheritanceList of schema inheritance

Page 74: Trends in Database Development: XML, .NET, WinFS

ContactsContacts

A common concept shared by everybodyA common concept shared by everybody

Page 75: Trends in Database Development: XML, .NET, WinFS

Web servicesWeb services

4 slides. Mention server side support4 slides. Mention server side support

Page 76: Trends in Database Development: XML, .NET, WinFS

DemoDemo

SQLXML HTTPSQLXML HTTP

Page 77: Trends in Database Development: XML, .NET, WinFS

New mappingNew mapping

Page 78: Trends in Database Development: XML, .NET, WinFS

SQLCLR SummarySQLCLR Summary

Richer programming model in database

Any .NET language, selected .NET frameworksTight integration with VS.NET

Deep integration SQL and .NET Runtime

Basis for security, reliability, scalability, performance

ADO.NET provider inside SQLCommon middle- and server-tier data access

Manageable and serviceableScripts, metadata, profiler events, performance counters

Richer programming model in database

Any .NET language, selected .NET frameworksTight integration with VS.NET

Deep integration SQL and .NET Runtime

Basis for security, reliability, scalability, performance

ADO.NET provider inside SQLCommon middle- and server-tier data access

Manageable and serviceableScripts, metadata, profiler events, performance counters

Page 79: Trends in Database Development: XML, .NET, WinFS

Debugging SQL Server “Yukon”Debugging SQL Server “Yukon”

Seamlessly step cross-languageT-SQL and SQL/CLR code

Set breakpoints anywhereBoth local and remote debuggingInspect anything

SQL typesUDTsManaged objects

Seamlessly step cross-languageT-SQL and SQL/CLR code

Set breakpoints anywhereBoth local and remote debuggingInspect anything

SQL typesUDTsManaged objects

Page 80: Trends in Database Development: XML, .NET, WinFS

ADO.NET Data Access SupportADO.NET Data Access Support

DataSet and DataSet and DataReaderDataReaderin ADO.NETin ADO.NET

ObjectSpacObjectSpaces in es in ADO.NETADO.NET

Technology Strengths Use if… Technology Strengths Use if…

SQLXML SQLXML ininADO.NETADO.NET

•Business level objectsBusiness level objects•Relational mapping via Relational mapping via metadatametadata•Decoupled from database Decoupled from database schemaschema•Smaller working set than Smaller working set than other object abstractionsother object abstractions•Interoperability. Format Interoperability. Format for the Web – B2B, A2Afor the Web – B2B, A2A•Sparse (semi-structured) Sparse (semi-structured) data data •XML Services e.g. XQuery, XML Services e.g. XQuery, XSDXSD•Relational mapping via Relational mapping via metadatametadata•Decoupled from database Decoupled from database schemaschema

•Relational (tabular) modelRelational (tabular) model•Highest performanceHighest performance•Explicit controlExplicit control•Fully exposes database Fully exposes database functionalityfunctionality

•You need a strong You need a strong business object layerbusiness object layer•You know the shape of You know the shape of the results you want to the results you want to work withwork with

•You need to query data from You need to query data from XML data sources e.g. XML Web XML data sources e.g. XML Web ServicesServices•You use vertical industry XML You use vertical industry XML schemas for content publishing schemas for content publishing e.g. XBRL, RIXML, FinXMLe.g. XBRL, RIXML, FinXML•You need to load XML You need to load XML documents into database tablesdocuments into database tables•You are using UI bound You are using UI bound controls for XMLcontrols for XML

•You are comfortable with You are comfortable with the relational modelthe relational model•You require maximum You require maximum control/performance/functioncontrol/performance/functionalityality•You are using UI bound You are using UI bound controlscontrols

Data is relational is objects is XML is DataData is relational is objects is XML is Data

Page 81: Trends in Database Development: XML, .NET, WinFS

.NET Framework IntegrationKey Features

.NET Framework IntegrationKey Features

Server-side programming environment for:User Defined Functions, Stored Procedures, TriggersUser Defined Types, user defined Aggregates

In-Proc Data Access (ADO.NET V2 - Whidbey)Common ADO .NET Programming Model

Both Mid-tier/data tier

SecurityIntegration of SQL and CLR securityThree levels of code access security

Safe, External-Access (verifiable), Unsafe

Tight integration with Visual StudioAuthoring, debugging, deployment, & profiling

Server-side programming environment for:User Defined Functions, Stored Procedures, TriggersUser Defined Types, user defined Aggregates

In-Proc Data Access (ADO.NET V2 - Whidbey)Common ADO .NET Programming Model

Both Mid-tier/data tier

SecurityIntegration of SQL and CLR securityThree levels of code access security

Safe, External-Access (verifiable), Unsafe

Tight integration with Visual StudioAuthoring, debugging, deployment, & profiling

Page 82: Trends in Database Development: XML, .NET, WinFS

Authoring/Debugging/DeployingAuthoring/Debugging/Deploying

New Visual Studio project type in “Whidbey” for “Yukon” managed codeServer debug integration

Full debugger visibilitySet breakpoints anywhere

Single step support: Between languages: T-SQL, C#, VB, & C++Between deployment tiers:

E.g. ASP.NET, through SQL Server stored proc call, & back to mid-tier

New Visual Studio project type in “Whidbey” for “Yukon” managed codeServer debug integration

Full debugger visibilitySet breakpoints anywhere

Single step support: Between languages: T-SQL, C#, VB, & C++Between deployment tiers:

E.g. ASP.NET, through SQL Server stored proc call, & back to mid-tier

Page 83: Trends in Database Development: XML, .NET, WinFS

.NET IntegrationKey Theme: Choice & Control.NET IntegrationKey Theme: Choice & Control

Choice of where to run logicDatabase, for logic that runs close to dataMid-tier, for logic that scales outSymmetric programming model

Leverage skills mid-tier & server

Safe extended stored proc replacement Choice of programming language

C#, VB.NET, & Managed C++, for a safe, modern execution environmentT-SQL enhancements continue

Right choice for data-intensive procedures

Choice of where to run logicDatabase, for logic that runs close to dataMid-tier, for logic that scales outSymmetric programming model

Leverage skills mid-tier & server

Safe extended stored proc replacement Choice of programming language

C#, VB.NET, & Managed C++, for a safe, modern execution environmentT-SQL enhancements continue

Right choice for data-intensive procedures

Page 84: Trends in Database Development: XML, .NET, WinFS

XML ScenariosSemi-structured storage…XML ScenariosSemi-structured storage…

XML DatatypeLoosely structured dataData with a dynamic schema

XML ViewsMixed data – structured/unstructuredXML stores w/o relational support challenged

XML DatatypeLoosely structured dataData with a dynamic schema

XML ViewsMixed data – structured/unstructuredXML stores w/o relational support challenged

First Name

Last Name

Address Phone XML data type

Page 85: Trends in Database Development: XML, .NET, WinFS

XML ViewsOverviewXML ViewsOverview

Default XML view of relational dataUser-defined XML views

Specified using schema mapping

Decouples mapping from domain specific schemas

Default XML view of relational dataUser-defined XML views

Specified using schema mapping

Decouples mapping from domain specific schemas

First Name

Last Name

Address Phone XML data type

XML ViewBulk

load

XQuery,Updates

Page 86: Trends in Database Development: XML, .NET, WinFS

Middle-Tier XML Views Middle-Tier XML Views

SQL Server “Yukon” XML data typeSparse (semi-structured) data

XML ViewsMixed data – structured/unstructured

XML View hides representation

SQL Server “Yukon” XML data typeSparse (semi-structured) data

XML ViewsMixed data – structured/unstructured

XML View hides representation

CustomerID

ContactName

Street City XML data type

XML ViewXML ViewXQuery andXQuery and

UpdatesUpdatesCustomer Table

Page 87: Trends in Database Development: XML, .NET, WinFS

Middle-Tier XML ViewsMiddle-Tier XML ViewsDeclarative syntax for mapping between XML and relational dataSupport for common database design patterns

Stored proc supportExtensibility mechanism with SQL queries.

XQuery over XML Viewsfor $i in

map:view(“nwind.msd”)//Customer where $i/CustomerID = “ALFKI” return $iIdentical mapping technology used by ADO.NET Objectspaces for objects

Declarative syntax for mapping between XML and relational dataSupport for common database design patterns

Stored proc supportExtensibility mechanism with SQL queries.

XQuery over XML Viewsfor $i in

map:view(“nwind.msd”)//Customer where $i/CustomerID = “ALFKI” return $iIdentical mapping technology used by ADO.NET Objectspaces for objects

Page 88: Trends in Database Development: XML, .NET, WinFS

XML View ExampleXML View ExampleCustomer Table

CustomerID

ContactName

Street

City

CustomerID

Customer

name

Street

CityCountry

Country

XSD - XML Schema Definition

MSD - Mapping Schema Definition

RSD - Relational Schema Definition

Page 89: Trends in Database Development: XML, .NET, WinFS

<ItemType Name="Person” BaseType="Core.Contact" ... > <Property Name="PersonalNames” Type="MultiSet“ MultiSetOfType="FullName“ Nullable="true"> <Property Name="AddressLine“ Type="WinFS.String"

Nullable="true"> <RelationshipType Name="Employment“ BaseType="WinFS.Relationship“ AllowsHolding="true“ AllowsEmbedding="false“ AllowsReference="true"> <Property Name=“IrisScan” Type=“WinFS.FileStream” …/></ItemType>

WinFS Schema

<ItemType Name="Person” BaseType="Core.Contact" ... > <Property Name="PersonalNames” Type="MultiSet“ MultiSetOfType="FullName“ Nullable="true"> <Property Name="AddressLine“ Type="WinFS.String" Nullable="true"> <RelationshipType Name="Employment“ BaseType="WinFS.Relationship“ AllowsHolding="true“ AllowsEmbedding="false“ AllowsReference="true"> <Property Name=“IrisScan” Type=“WinFS.FileStream” …/></ItemType>

WinFS Schema

ItemId Name Addresses

Street City State Zip

Street City State Zip

Street City State Zip

IrisScan

FirstName LastName

Table View of Person

NTFS stream

ExampleExample public partial class Person_t : Item { private String _AddressLine; private PersonalNames _Name; public String AddressLine { get { return _AddressLine; } set { _AddressLine = value; } } public Relationship Employment {get { …} // cached or select statement set { …} private FileStream_IrisScan;…}

CLR Assembly public partial class Person_t : Item { private String _AddressLine; private PersonalNames _Name; public String AddressLine { get { return _AddressLine; } set { _AddressLine = value; } } public Relationship Employment {get { …} // cached or select statement set { …} private FileStream_IrisScan;…}

CLR Assembly

ItemId Name Addresses

Street City State Zip

Street City State Zip

Street City State Zip

IrisScan

FirstName LastName

Table View of Person

NTFS stream

ExampleExample

Page 90: Trends in Database Development: XML, .NET, WinFS

API ExamplesAPI Examples

VB Managed APIDim personItem As PersonFor Each personItem In Person.FindAll(context, “PersonalNames.Surname=’Smith’)

...Next

VB Managed APIDim personItem As PersonFor Each personItem In Person.FindAll(context, “PersonalNames.Surname=’Smith’)

...Next

T-SQLselect p._Item from [System.Storage.Contacts.Store].[Person] p

where exists (select * from unnest (p.PersonalNames) n

where n.Surname=‘Smith')

T-SQLselect p._Item from [System.Storage.Contacts.Store].[Person] p

where exists (select * from unnest (p.PersonalNames) n

where n.Surname=‘Smith')

Page 91: Trends in Database Development: XML, .NET, WinFS

WinFS ServicesFilesystem WinFS ServicesFilesystem

“File-backed” ItemsItems with traditional filestream parts withinUses real NTFS streams and file handlesAny file can be imported into WinFS as a File-back Item

WinFS is backwards compatible with Win32

“File-backed” ItemsItems with traditional filestream parts withinUses real NTFS streams and file handlesAny file can be imported into WinFS as a File-back Item

WinFS is backwards compatible with Win32

Fram

ework

Models

Core WinFS ItemsItems

RelationshipsRelationships

ExtensionsExtensionsFilesystem Srvcs (Handlers, …)Filesystem Srvcs (Handlers, …)

OperationsOperations

Data Model

NTFSNTFS

Relational EngineRelational Engine

ServicesPeoplePeople

DocumentsDocuments

……InfoAgent (Rules, …)InfoAgent (Rules, …)

Synchronization(WinFS, …)Synchronization(WinFS, …)

Schemas

XMLXMLAPIs

T/SQLT/SQLObjectsObjects

Page 92: Trends in Database Development: XML, .NET, WinFS

Finding Items In WinFSFinding Items In WinFS

OPathSimple query language in the object domainUses paradigm familiar to OO programmers

SupportsSimple equalitiesWild cards‘IN’, ‘LIKE’ operatorsDate expressionsTraverse relationshipsGrouping expressionsSimple math expressions (+, -)

Example“(DisplayName = ‘Sean Chai’) || (DisplayName like ‘K%’ )”

OPathSimple query language in the object domainUses paradigm familiar to OO programmers

SupportsSimple equalitiesWild cards‘IN’, ‘LIKE’ operatorsDate expressionsTraverse relationshipsGrouping expressionsSimple math expressions (+, -)

Example“(DisplayName = ‘Sean Chai’) || (DisplayName like ‘K%’ )”

Page 93: Trends in Database Development: XML, .NET, WinFS

User BenefitsUser BenefitsFind my stuff

“The big presentation I got from Toby I was working on last week”

One view of dataIM Toby, Hotmail Toby, Corporate Toby, …

Exposing relationships Doc authors, Meeting attendees, Meeting Locations, Location occupants…

Find my stuff“The big presentation I got from Toby I was working on last week”

One view of dataIM Toby, Hotmail Toby, Corporate Toby, …

Exposing relationships Doc authors, Meeting attendees, Meeting Locations, Location occupants…

Page 94: Trends in Database Development: XML, .NET, WinFS

Developer BenefitsDeveloper Benefits

Populated, well-defined data definitions (types)You don’t have to build your own store or APIApplications can create and share dataThe storage subsystem is Extensible

It’s much easier to build a smart connected applicationApplications can create and share types

Populated, well-defined data definitions (types)You don’t have to build your own store or APIApplications can create and share dataThe storage subsystem is Extensible

It’s much easier to build a smart connected applicationApplications can create and share types

Page 95: Trends in Database Development: XML, .NET, WinFS

Metadata HandlersMotivationMetadata HandlersMotivation

PromotionEnd-users don’t need to re-tag their content with metadata

WinFS automatically pulls it out of filesExisting applications continue to write to files

Appropriate metadata surfaces in WinFS items

DemotionWinFS apps use one API to write pure WinFS and file-backed items

WinFS demotes metadata back to filesAllows interop between legacy and new applicationsProvides fidelity of metadata through moves/copies

PromotionEnd-users don’t need to re-tag their content with metadata

WinFS automatically pulls it out of filesExisting applications continue to write to files

Appropriate metadata surfaces in WinFS items

DemotionWinFS apps use one API to write pure WinFS and file-backed items

WinFS demotes metadata back to filesAllows interop between legacy and new applicationsProvides fidelity of metadata through moves/copies

Page 96: Trends in Database Development: XML, .NET, WinFS

Data Requirements in Next Generation ApplicationsData Requirements in Next Generation ApplicationsModel complex objects

Complex structureInheritanceUnstructured, XML and Structured data

Rich RelationshipsValue-based Link basedWinFS provides a built in model with more services for complex objects

Rich and Common QueryCommon across client and serverCommon across different typed of data – SQL, Objects, XML

Granular operationsCopy, MoveBackup/RestoreSecurity

Rich organization Hierarchical Namespace

Active Notifications and Data SynchronizationIntegrated Business logic

Optimistic concurrency control and API mapping

Model complex objectsComplex structureInheritanceUnstructured, XML and Structured data

Rich RelationshipsValue-based Link basedWinFS provides a built in model with more services for complex objects

Rich and Common QueryCommon across client and serverCommon across different typed of data – SQL, Objects, XML

Granular operationsCopy, MoveBackup/RestoreSecurity

Rich organization Hierarchical Namespace

Active Notifications and Data SynchronizationIntegrated Business logic

Optimistic concurrency control and API mapping

Page 97: Trends in Database Development: XML, .NET, WinFS

Creating API for a SchemaCreating API for a SchemaCreate WinFS schema in XML formatSchema compiler generates API assemblyYou can add your own “helper” membersThe assemblies are installed into a WinFS store

WinFS types are registered as UDTs

Views and other database objects are created

Create WinFS schema in XML formatSchema compiler generates API assemblyYou can add your own “helper” membersThe assemblies are installed into a WinFS store

WinFS types are registered as UDTs

Views and other database objects are created

WinFSSchema

CLR Complier

Code for Helper

Members

WinFSSchemaCompiler

Code for Standard

APIAPI

Classes

Page 98: Trends in Database Development: XML, .NET, WinFS

Schema compilation processSchema compilation process

WinFS schemas are defined using XML syntax The WinFS schema compilation process generates C# code from the WinFS Schema fileThe C# source files are compiled into assembliesThe assemblies are installed into a WinFS store

WinFS types are registered as UDTs

Views and other database objects are created

WinFS schemas are defined using XML syntax The WinFS schema compilation process generates C# code from the WinFS Schema fileThe C# source files are compiled into assembliesThe assemblies are installed into a WinFS store

WinFS types are registered as UDTs

Views and other database objects are createdWinFS

SchemaCLR

Complier

WinFSSchemaCompiler

C# code for UDTs

SchemaAssemblies

WinFSStore

Page 99: Trends in Database Development: XML, .NET, WinFS

Data Model Mapping OverviewData Model Mapping Overview

A WinFS schema is mapped to a SQL schemaA CLR class is generated for each Item, Nested, Extension Relationship typeThe classes are registered as SQL User Defined Types (UDTs)Search views are provided for each Item, Extension and Relationship typeUpdates are enabled through the WinFS Update API operations

CreateItem, CreateRelationship, CreateExtensionUpdateItem, UpdateRelationship, UpdateExtensionDeleteRelationship, DeleteExtension

A WinFS schema is mapped to a SQL schemaA CLR class is generated for each Item, Nested, Extension Relationship typeThe classes are registered as SQL User Defined Types (UDTs)Search views are provided for each Item, Extension and Relationship typeUpdates are enabled through the WinFS Update API operations

CreateItem, CreateRelationship, CreateExtensionUpdateItem, UpdateRelationship, UpdateExtensionDeleteRelationship, DeleteExtension

Page 100: Trends in Database Development: XML, .NET, WinFS

WinFS Data ModelWinFS Data Model

The WinFS Data Model describes the shape of the data stored in WinFSthe constraints on the dataassociations between data

WinFS world is comprised of items, relationships and extensionsItems are the primary objects that applications work onItems can be associated with other items via relationshipsItems can be extended with extensions (or subclass)

The WinFS Data Model describes the shape of the data stored in WinFSthe constraints on the dataassociations between data

WinFS world is comprised of items, relationships and extensionsItems are the primary objects that applications work onItems can be associated with other items via relationshipsItems can be extended with extensions (or subclass)

Page 101: Trends in Database Development: XML, .NET, WinFS

WinFS Type ExampleWinFS Type Exampleusing Contact =

System.Storage.Contact;using Core = System.Storage.Core;using Base = System.Storage;

type Contact.Address : Base.NestedType {string Street;string City;string Zip;…

}type Contact.Person : Core.Contact

{datetime BirthDate;binary[] Picture;Address BirthAddress;MultiSet<Address> Addresses;…

}type Contact.Organization :

Core.Contact {string OrganizationName;…

}

using Contact = System.Storage.Contact;

using Core = System.Storage.Core;using Base = System.Storage;

type Contact.Address : Base.NestedType {string Street;string City;string Zip;…

}type Contact.Person : Core.Contact

{datetime BirthDate;binary[] Picture;Address BirthAddress;MultiSet<Address> Addresses;…

}type Contact.Organization :

Core.Contact {string OrganizationName;…

}

Contact

OrganizationPerson

Item

Page 102: Trends in Database Development: XML, .NET, WinFS

SQL OR Extensions - Smart SerializationSQL OR Extensions - Smart Serialization

SQLCLR types leverage a custom serialization library (SL)

Efficient access to properties of embedded objects

Avoids object construction or method invocations for simple property getters and settersProperty and field access translates to compiled field accessors

New structured serialization formatUnderstands inheritance, embedded types, collection typesInternal to SQL

Provides “record like” performance for accessing object properties

SQLCLR types leverage a custom serialization library (SL)

Efficient access to properties of embedded objects

Avoids object construction or method invocations for simple property getters and settersProperty and field access translates to compiled field accessors

New structured serialization formatUnderstands inheritance, embedded types, collection typesInternal to SQL

Provides “record like” performance for accessing object properties

Page 103: Trends in Database Development: XML, .NET, WinFS

SQL OR Extensions - Smart SerializationSQL OR Extensions - Smart Serialization

Example:

SELECT FirstName, LastName, …FROM [System.Storage.Contact.Store].Contact cWHERE BirthAddress.City = ‘Seattle’

Fetching HomeAddress.City does not require the materialization of the Address objectProperties retrieved by directly “cracking” the serialized form

Example:

SELECT FirstName, LastName, …FROM [System.Storage.Contact.Store].Contact cWHERE BirthAddress.City = ‘Seattle’

Fetching HomeAddress.City does not require the materialization of the Address objectProperties retrieved by directly “cracking” the serialized form

Page 104: Trends in Database Development: XML, .NET, WinFS

SQL OR Extensions - CollectionsSQL OR Extensions - Collections

SQL supports a generic collection type MULTISET<T>Properties can be declared using collectionsTreated from SQL as “nested table”Queryable using UNNEST table valued function

SELECT c.FirstName, c.LastName, A.addr.City, A.addr.ZipFROM [System.Storage.Contact.Store].Contact cCROSS APPLY UNNEST(c.Addresses) AS A(addr)

Current investigating replacing the MultiSet collection with IList<T> (to support ordering)

SQL supports a generic collection type MULTISET<T>Properties can be declared using collectionsTreated from SQL as “nested table”Queryable using UNNEST table valued function

SELECT c.FirstName, c.LastName, A.addr.City, A.addr.ZipFROM [System.Storage.Contact.Store].Contact cCROSS APPLY UNNEST(c.Addresses) AS A(addr)

Current investigating replacing the MultiSet collection with IList<T> (to support ordering)

Page 105: Trends in Database Development: XML, .NET, WinFS

Media SchemasMedia Schemas

...Record:AudioRecord ◄TrackAlbum.Album

Audio.CachedAlbum

...Habits:ListeningHabits ◄ListenedTrack.Track

Audio.Track

...

Audio.PlayList

...

Audio.PlatterTrack

...Contact:Contact ►ContactsInPicture.PictureOtherVersion:Picture ◄►PictureOtherVersions.Picture

Image.Picture

...Metadata:CachedTrack ►SuggestedMetadata.RecordAlbum:CachedAlbum ►TrackAlbum.Record

Audio.AudioRecord

...

Video.RecordedTV

...Record:AudioRecord ◄SuggestedMetadata.Metadata

Audio.CachedTrack

...Distributor:Contact ►ContentDistributor.DocumentArt:Document ►EffectiveBackCoverArt.DocumentArt:Document ►EffectiveFrontCoverArt.DocumentLogo:Document ►MetadataProviderLogo.Document

Media.Document

...Location:Location ►PhotoLocation.Photo

Image.Photo

...Clip:VideoClip ►Clips.Video

Video.VideoRecord