Title: Introduction to ADO'NET ObjectSpaces
1Introduction to ADO.NET ObjectSpaces Alex
ThissenTwice IT Training
2Agenda
- What is ADO.NET ObjectSpaces?
- ObjectSpaces architecture
- Mappings
- Common classes
- OPath query language
- Questions and Answers
3What is ObjectSpaces?
- Object-Relational framework
- Abstraction layer between
- objects from application logic
- data source
- Extra layer on top of ADO.NET
- Non-intrusive for object model
- Dynamically builds SQL statements based on XML
definitions of objects and database
4Overview ObjectSpaces architecture
5Three mapping files
- Object Schema Document (.osd)
- Defines business objects and members
- Specifies relations between types of objects
- Relational Schema Document (.rsd)
- Defines tables and views
- Mapping Schema Document (.msd)
- Combines OSD and RSD
- Maps between objects and tables
- Also specifies how object-relations map to
table-relationships
6Types of relationships
- Object relationships
- One to One, One to Many, Many to Many
- Inheritance
- Objects to Table mappings
- One object stored in one or more tables
- Multiple objects stored in one table
7DEMO
- Business objects
- Object Mapper Utility
8(No Transcript)
9ObjectSet
- In-memory set of objects from source
- Resembles DataSet
- Keeps original values for optimistic concurrency
- Can be bound to data controls
- Streamable as XML (DiffGram style)
- Automatic tracking of objects
10ObjectReader
- Provides a stream of objects from source
- Enumerate using foreach loop or while loop
- Is forward-only (not read-only)
11ObjectSpace class
- Handles communication to and from data source
- Supports
- State management
- Transactions
- Needs
- One or more DB connections (ObjectSources)
- Mapping file (MappingSchema)
- Retrieve objects using
- GetObject, GetObjectSet, GetObjectReader
12ObjectQuery
- Query that specifies search criteria for
retrieving objects - GetObject, GetObjectReader, GetObjectSet
- Needs three parameters
- Type of object to retrieve
- OPath query expression
- Span (depth) of object hierarchy to return
ObjectQuery oq new ObjectQuery(typeof(Posting),
"ltOPath expressiongt", "ltSpangt") ObjectReader
or ObjectSpace.GetObjectReader(oq)
13ObjectContext
- Implicitly used by ObjectSpace and ObjectSet
- Manages object identity
- When object is requested that has been returned
before, same object reference is used - Also works for links between objects
- Weak references are used
- More advanced scenarios work with ObjectContext
explicitly
14OPath Query language
- OPath expressions are used to retrieve subsets of
objects from source - Similar to XPath expressions
- Filtering using predicates
- Navigate object relations with dot (.) notation
// Some examples OrdersFreight gt
5.Details.Quantity gt 50 Customer.AddressState
Like 'A-C' Customer.Country 'USA' AND
Customer.Region 'WA' AddressState In ('WA',
'OR', 'ID') IIF(Gender 'M', 67, 72) - Age lt
Term Id Like ? AND OrdersFreight gt ?
15DEMO
- Retrieving objects
- ObjectSet
- Creating and storing objects
16Advanced features
- Delayed loading of nested objects
- Collections are kept inside ObjectList instead of
classes like ArrayList - "Read-only" objects
- Not tracked by an ObjectContext
- Optimal performance
- Compiled queries
17Things to keep in mind
- "This" release only supports SQL Server 2000 or
later as datasource - Although data source should implement
IDbConnection - Cannot run (yet) from "in-process" Yukon stored
procedures - Performance will be similar to working with
DataAdapters and DataSets
18Resources and links
- PDC 2003 Samples
- ObjectSpaces Mapper Utility
- Object Persistence Sample
- System.Data.ObjectSpaces documentation
- Mail to osfdbk_at_microsoft.com
19Questions and Answers