SlideShare ist ein Scribd-Unternehmen logo
1 von 25
Week 7 – WCF RIA Services Overview Jim LaVine jim.lavine @gmail.com
Remaining Schedule 1-8 Exposing and consuming querying services 1/15 Updating data 1/22 Business Logic and validation
Agenda Domain query rules The DomainContext Class Asynchronous loading Client-side data caching Shaping data in the client Retrieving object hierarchies A peak under the hood
Design-time workflow Server project Client project Domain Service CRUD Domain Service Domain Context Load 2 Invoke Custom  logic Build Entity Container Data model Metadata Entity Metadata Entity proxy type 3 Metadata Entity Metadata Entity proxy type Metadata Entity Metadata Entity proxy type 1 DAL Bindable UI Views L2S EF REST/SOAP POCO 4
Domain query operation rules IEnumerable IQueryable <T>     [EnableClientAccess()]    public class ChinookDomainService : LinqToEntitiesDomainService<ChinookEntities>    {                public  IEnumerable<Invoice> GetInvoiceByCustomer(int customerId)        {    return ObjectContext.Invoices.Where(c => c.CustomerId == customerId); }        public Customer GetCustomerById(int customerId)        {    return ObjectContext.Customers.Where(c => c.CustomerId == customerId); }    } public Supported types Entity          public  IEnumerable<Customers> GetCustomersByJoinData(DateTimemindate, 	DateTimemaxdate)        {     return ObjectContext.Customers.Where(c => c.JoinDate >= mindate && 	c.JoinDate <= maxdate);          } No Overloads
         public class  Customers        {                    [Key] public int CustomerId { get; set; }                 public string FName{ get; set; }                  . . .         } Domain query operation rules Identity
Convention vs. configuration Query operation explicit marking : QueryAttribute Signature match : returns IQueryable<T>, IEnumerable<T>, T QueryAttribute parameters IsComposable ResultLimit HasSideEffects                  [Query] public Iqueryable<Customers>  GetCustomersByState (BillingStatestate)  { . . . } public Iqueryable<Customers>  GetCustomersByState (BillingStatestate)  { . . . }               [Query (IsComposable=false)] public SalesPerson GrabTopSalesperson (intyear)  { . . . }
Demo Defining domain queries
Code generation l Server assemblies Silverlight Client Silverlight client Namespace DomainContext types Query factory methods DomainService types [EnableClientAccess] Public methods Namespace Class name Public props Entity type Entity type Entity type Entity proxy Entity proxy Entity proxy InotifyPropertyChanged Validation Metadata Custom Attribute Metadata class Custom Attribute
The typed DomainContext class Constructors Query proxy methods Entity proxy properties Entity container factory
Demo Examining generated classes
Asynchronous loading ChinookDomainContext ctx =  newChinookDomainContext(); varquery = ctx.GetInvoicesByCustomer (1) ; LoadOperation<Invoice>op = ctx.Load(query); EntityQuery <Invoice> CustomerGrid.ItemsSource = op.Entities LoadOperation <Invoice> IEnumerable<Invoice>
The Load method Load method overloads Load(EntityQuery<TEntity>) Load(EntityQuery<TEntity>, LoadBehavior, Callback, UserState) Load(EntityQuery<TEntity>, Callback, UserState) Load(EntityQuery<TEntity>, ThrowOnError) Load(EntityQuery<TEntity>, LoadBehavior, ThrowOnError) LoadOperation<Invoice> op = ctx.Load<Invoice>(query, lo => { /* Check for errors, bind to UI, do work */}, null); ctx.Load<Invoice>(query).Completed += newEventHandler(LoadComplete); voidLoadComplete(object sender, EventArgs e) {/* Check for errors, bind to UI, do work */ }
LoadOperation Load Operation: ,[object Object]
Entities
EntityQuery
TotalEntityCountOperationBase: ,[object Object]
IsComplete, Completed, event
Cancel(), CanCancel, IsCanceled
Error, HasError,[object Object]
Caching query results EntitySet property Load() Entity Container Domain Context Query Results Send query Query Results Entity Set Entity Set Entity Set Domain Service INotifyProperty Changed Change tracking Validation Data binding Updating Entity Entity Entity
Demo Binding to cached data
Load options Changes (local) Changes (remote) Load() LoadBehavior: -KeepCurrent -MergeIntoCurrent -RefreshCurrent Entity Container Entity Set ?
Demo Using LoadBehavior
Client side data shaping EntityQueryable (extension) QueryName Parameters Query IsComposable EntityQuery<T> e.g. GetProductsQuery() LINQ operators (Where, Skip,Take, OrderBy) LINQ operators (Where, Skip,Take, OrderBy) Client Server Server query + Client-side query combined Domain Service

Weitere ähnliche Inhalte

Ähnlich wie RIA services exposing & consuming queries

Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...SharePoint Saturday NY
 
ADO.NET Data Services
ADO.NET Data ServicesADO.NET Data Services
ADO.NET Data Servicesukdpe
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationMark Gu
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Igor Moochnick
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik TambekarPratik Tambekar
 
SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...Liam Cleary [MVP]
 
Web services in java
Web services in javaWeb services in java
Web services in javamaabujji
 
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?SegFaultConf
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWAREFIWARE
 
Introduction to the Client OM in SharePoint 2010
Introduction to the Client OM in SharePoint 2010Introduction to the Client OM in SharePoint 2010
Introduction to the Client OM in SharePoint 2010Ben Robb
 
A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & RESTSanthu Rao
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and PracticesLaunchAny
 
Android chapter18 c-internet-web-services
Android chapter18 c-internet-web-servicesAndroid chapter18 c-internet-web-services
Android chapter18 c-internet-web-servicesAravindharamanan S
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Jonas Follesø
 
SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)Kashif Imran
 
Microservices design patterns
Microservices design patternsMicroservices design patterns
Microservices design patternsMasashi Narumoto
 
Rest API and Client OM for Developer
Rest API and Client OM for DeveloperRest API and Client OM for Developer
Rest API and Client OM for DeveloperInnoTech
 

Ähnlich wie RIA services exposing & consuming queries (20)

Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
Lyudmila Zharova: Developing Solutions for SharePoint 2010 Using the Client O...
 
ADO.NET Data Services
ADO.NET Data ServicesADO.NET Data Services
ADO.NET Data Services
 
State management
State managementState management
State management
 
Developing Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web ApplicationDeveloping Next-Gen Enterprise Web Application
Developing Next-Gen Enterprise Web Application
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)Ado.Net Data Services (Astoria)
Ado.Net Data Services (Astoria)
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...SharePoint Saturday The Conference DC - How the client object model saved the...
SharePoint Saturday The Conference DC - How the client object model saved the...
 
Web services in java
Web services in javaWeb services in java
Web services in java
 
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?Andrzej Ludwikowski -  Event Sourcing - co może pójść nie tak?
Andrzej Ludwikowski - Event Sourcing - co może pójść nie tak?
 
Developing your first application using FIWARE
Developing your first application using FIWAREDeveloping your first application using FIWARE
Developing your first application using FIWARE
 
Introduction to the Client OM in SharePoint 2010
Introduction to the Client OM in SharePoint 2010Introduction to the Client OM in SharePoint 2010
Introduction to the Client OM in SharePoint 2010
 
A presentation on WCF & REST
A presentation on WCF & RESTA presentation on WCF & REST
A presentation on WCF & REST
 
Event-Based API Patterns and Practices
Event-Based API Patterns and PracticesEvent-Based API Patterns and Practices
Event-Based API Patterns and Practices
 
Android chapter18 c-internet-web-services
Android chapter18 c-internet-web-servicesAndroid chapter18 c-internet-web-services
Android chapter18 c-internet-web-services
 
Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008Silverlight 2 for Developers - TechEd New Zealand 2008
Silverlight 2 for Developers - TechEd New Zealand 2008
 
SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)SharePoint Client Object Model (CSOM)
SharePoint Client Object Model (CSOM)
 
B_110500002
B_110500002B_110500002
B_110500002
 
Microservices design patterns
Microservices design patternsMicroservices design patterns
Microservices design patterns
 
Rest API and Client OM for Developer
Rest API and Client OM for DeveloperRest API and Client OM for Developer
Rest API and Client OM for Developer
 

Mehr von iedotnetug

Ria services updating data
Ria services updating dataRia services updating data
Ria services updating dataiedotnetug
 
IEDOTNETUG Silverlight Class Week 6
IEDOTNETUG Silverlight Class Week 6IEDOTNETUG Silverlight Class Week 6
IEDOTNETUG Silverlight Class Week 6iedotnetug
 
Silverlight week5
Silverlight week5Silverlight week5
Silverlight week5iedotnetug
 
Silverlight Input Handling
Silverlight Input HandlingSilverlight Input Handling
Silverlight Input Handlingiedotnetug
 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2iedotnetug
 
Inland Empire .NET User's Group Silverlight Class
Inland Empire .NET User's Group Silverlight ClassInland Empire .NET User's Group Silverlight Class
Inland Empire .NET User's Group Silverlight Classiedotnetug
 

Mehr von iedotnetug (6)

Ria services updating data
Ria services updating dataRia services updating data
Ria services updating data
 
IEDOTNETUG Silverlight Class Week 6
IEDOTNETUG Silverlight Class Week 6IEDOTNETUG Silverlight Class Week 6
IEDOTNETUG Silverlight Class Week 6
 
Silverlight week5
Silverlight week5Silverlight week5
Silverlight week5
 
Silverlight Input Handling
Silverlight Input HandlingSilverlight Input Handling
Silverlight Input Handling
 
Silverlight week2
Silverlight week2Silverlight week2
Silverlight week2
 
Inland Empire .NET User's Group Silverlight Class
Inland Empire .NET User's Group Silverlight ClassInland Empire .NET User's Group Silverlight Class
Inland Empire .NET User's Group Silverlight Class
 

Kürzlich hochgeladen

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 

Kürzlich hochgeladen (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 

RIA services exposing & consuming queries

  • 1. Week 7 – WCF RIA Services Overview Jim LaVine jim.lavine @gmail.com
  • 2. Remaining Schedule 1-8 Exposing and consuming querying services 1/15 Updating data 1/22 Business Logic and validation
  • 3. Agenda Domain query rules The DomainContext Class Asynchronous loading Client-side data caching Shaping data in the client Retrieving object hierarchies A peak under the hood
  • 4. Design-time workflow Server project Client project Domain Service CRUD Domain Service Domain Context Load 2 Invoke Custom logic Build Entity Container Data model Metadata Entity Metadata Entity proxy type 3 Metadata Entity Metadata Entity proxy type Metadata Entity Metadata Entity proxy type 1 DAL Bindable UI Views L2S EF REST/SOAP POCO 4
  • 5. Domain query operation rules IEnumerable IQueryable <T>     [EnableClientAccess()]    public class ChinookDomainService : LinqToEntitiesDomainService<ChinookEntities>    {                public  IEnumerable<Invoice> GetInvoiceByCustomer(int customerId)        {    return ObjectContext.Invoices.Where(c => c.CustomerId == customerId); }        public Customer GetCustomerById(int customerId)        {    return ObjectContext.Customers.Where(c => c.CustomerId == customerId); }    } public Supported types Entity          public  IEnumerable<Customers> GetCustomersByJoinData(DateTimemindate, DateTimemaxdate)        {     return ObjectContext.Customers.Where(c => c.JoinDate >= mindate && c.JoinDate <= maxdate);  } No Overloads
  • 6.          public class  Customers        {     [Key] public int CustomerId { get; set; }  public string FName{ get; set; }  . . . } Domain query operation rules Identity
  • 7. Convention vs. configuration Query operation explicit marking : QueryAttribute Signature match : returns IQueryable<T>, IEnumerable<T>, T QueryAttribute parameters IsComposable ResultLimit HasSideEffects          [Query] public Iqueryable<Customers>  GetCustomersByState (BillingStatestate)  { . . . } public Iqueryable<Customers>  GetCustomersByState (BillingStatestate)  { . . . } [Query (IsComposable=false)] public SalesPerson GrabTopSalesperson (intyear)  { . . . }
  • 9. Code generation l Server assemblies Silverlight Client Silverlight client Namespace DomainContext types Query factory methods DomainService types [EnableClientAccess] Public methods Namespace Class name Public props Entity type Entity type Entity type Entity proxy Entity proxy Entity proxy InotifyPropertyChanged Validation Metadata Custom Attribute Metadata class Custom Attribute
  • 10. The typed DomainContext class Constructors Query proxy methods Entity proxy properties Entity container factory
  • 12. Asynchronous loading ChinookDomainContext ctx = newChinookDomainContext(); varquery = ctx.GetInvoicesByCustomer (1) ; LoadOperation<Invoice>op = ctx.Load(query); EntityQuery <Invoice> CustomerGrid.ItemsSource = op.Entities LoadOperation <Invoice> IEnumerable<Invoice>
  • 13. The Load method Load method overloads Load(EntityQuery<TEntity>) Load(EntityQuery<TEntity>, LoadBehavior, Callback, UserState) Load(EntityQuery<TEntity>, Callback, UserState) Load(EntityQuery<TEntity>, ThrowOnError) Load(EntityQuery<TEntity>, LoadBehavior, ThrowOnError) LoadOperation<Invoice> op = ctx.Load<Invoice>(query, lo => { /* Check for errors, bind to UI, do work */}, null); ctx.Load<Invoice>(query).Completed += newEventHandler(LoadComplete); voidLoadComplete(object sender, EventArgs e) {/* Check for errors, bind to UI, do work */ }
  • 14.
  • 17.
  • 20.
  • 21. Caching query results EntitySet property Load() Entity Container Domain Context Query Results Send query Query Results Entity Set Entity Set Entity Set Domain Service INotifyProperty Changed Change tracking Validation Data binding Updating Entity Entity Entity
  • 22. Demo Binding to cached data
  • 23. Load options Changes (local) Changes (remote) Load() LoadBehavior: -KeepCurrent -MergeIntoCurrent -RefreshCurrent Entity Container Entity Set ?
  • 25. Client side data shaping EntityQueryable (extension) QueryName Parameters Query IsComposable EntityQuery<T> e.g. GetProductsQuery() LINQ operators (Where, Skip,Take, OrderBy) LINQ operators (Where, Skip,Take, OrderBy) Client Server Server query + Client-side query combined Domain Service
  • 27. Retrieving object hierarchies Server Client Server-side Entity type Domain Service IQuerable<foo> GetFoos() Entity Container [IncludeAttribute] Include foo1 foo1 [Association] new props Metadata Class
  • 29. A look behind the scenes Domain Context Domain Service BeginQuery() Domain Service HostFactory Web Domain Client Domain ServiceHost Operation Description QueryResult<T> WCF Channel Factory WCF Service Contract REST/binary endpoint WCF Service Contract Virtual.SVC file <%@ServiceHost Service=“XYZService Factory=“System.Web.Ria. DomainServiceHostFactory”%> WCF Client Channel DomainService HttpModule
  • 30. Summary Integrated Infrastructure Signature-based conventions Metadata-specific object heirarchies Simplified asynchronous calls Client-side data caching Integrateing data shaping REST-based default configuration

Hinweis der Redaktion

  1. Once the query methods are created in the domain service, let’s see what happens at build time.The build process extension provided by the framework goes through the assemblies in the server project and looks at each service derived class to check whether the EnableClientAccess attribute is present. If so it creates a matching domain context in the Silverlight application for each domain service it finds on the server. The domain context has the same namespace as its server counterpart.Then the tooling looks at each publically exposed query methods in the domain service and it creates a matching query factory method in the domain context on the client.Each query operation that is exposed is examined for the entity type that it returns. As we mentioned before, entity types are concrete classes that have one or more properties annotated with a key attribute and these classes may be generated automatically by the data layer depending what you choose to use.The tooling creates an entity client proxy type for each entity type exposed on the server.The client type has the same namespace and class name as the server entity and exposes the same public members.Code generation provides the client=side proxy with data binding capability through the INotifyPropertyChanged interface and validation capability through INotifyDataErrorInfo. We’ll look at validation in two weeks.Custom attributes that are applied server-side are reflected on the client provided that the appropriate assemblies are made available to the client.Server-side metadata is merged with the entity type and so it is reflected directly in the client-side entity proxies.
  2. Probably the most important class generated for us by the build process is the typed domain context. The domain context is the chief orchestrator on the client.Among its generated members we find a series of constructors that allow us to pass various pieces of information to the class such as WCF service uri information, or a domain client instance which is a client side base class that is used to communicate with the server using a specific communication channelThe domain context also contains a set of query factory methods which return query proxies that match the server-side query operations that we’ve defined on the server.Also generated for us is a set of properties that give us access to client-side entity proxies.We also have an entity container factory method which creates an entity container instance
  3. Let’s examine how the querying mechanism actually works.When we need to retrieve data from the server what we do is make an asynchronous call from the client using one of the load methods that are exposed by the domain context base class.First we get an instance of the generated typed domain context class.Next we grab one of the client-side proxy queries through one of the query factory methods generated for in the domain context class. That proxy class represents one of the server-side queries we want to invoke.The actual type of that query is EntityQuery. The EntityQuery class encapsulates information about the server query we want to call. We can extend that query through Linq composition right here on the client before sending the query back to the server.Once we get a hold of the query proxy, we pass it to one of the load methods provided by the domain context class which will then send the query data across the network through the client-side infrastructure and then through the WCF infrastructure.When the load call is made, the load method immediately returns an instance of the LoadOperation class. The load operation object represents an ongoing asynchronous load operation.After the call returns, we can access the results of the query asynchronously through load operation entities property. In Silverlight we can bind to that property using a datagrid for example.Now asynchronous is the key word here. It is important to remember that, so lets take a closer look at how that works.
  4. There are actually 5 overloads of the load method that can be called. All of them take an EntityQuery parameter which represents the query method invocation.Two of them allow us to pass a completion callback and two allow us to specify how we want the results of the query to update the client-side cache through the LoadBehavior parameter.The overloads that allow a callback are very useful for dealing with the asynchronous nature of the load call. We specify a callback method that the load operation will call whenever it returns.There are at least two ways to specify a callback:One is to pass a delegate or lambda expression as a parameter to the load method. We also pass custom state information to the UserState parameter or you can pass null if none is required.Another way to specify callback is the handle to load operation completed event. Note that you can use an anonymous method or lambda expression for this.All these overloads return a LoadOperation Object, so lets zoom in on that object for a second
  5. The load operation exposes an Entities and an AllEntities property which we use to retrieve the loaded data. Through the Entities property we can access the top level entities in the return results set, as well as nested entities within those top level ones. Note that when we use this property, the nested entities get loaded on demand from the client-side entity container provided of course that the object tree has previously been loaded from the server. The AllEntities property on the other hand, gives us access to all the entities in the hierarchy in a flat manner.Load operation also has an EntityQuery property which stores the entity query instance that was passed by the load method, and remember that EntityQuery encapsulates the server-side query that we are invoking,Also the result count returned by the server can be retrieved by the load operation TotalEntityCount property.Load operation ultimately derives from OperationBase, which is the base class for all operation types in the framework including submit and invoke operations which we’ll see next week.OperationBase implements INotifyPropertyChanged so it knows how to raise notifications when the operations complete status is updated and that’s what enables us to bind data to a data grid to the load operation object even before the load call has completed.OperationBase also provides operation canceling and error handling capabilities.
  6. Once the asynchronous load call returns from the server, the properties of the load operation instance returned by the load method are populated, but there is another important thing that occurs when the server call returns.The domain context passes the data retrieved by the load call to the entity container for caching on the client.You may recall from last week that Ria services architecture defines a stateful client. State is largely maintained through the entity container in collaboration with the domain context and the entity sets.Entity sets are IEnumerable collections of entities in which the entity container caches the results of the instances. This means we can continue to access the loaded data even after the load call is exited and we do that through a bunch of public properties exposed by the domain context that give us access to the entity sets.Each of these properies actually returns a list of entities stored in the client cache which is the entity container.The entity container manages the list and tracks changes in them.Entity sets contain entity instances. Remember the tooling has generated in the domain context some entity proxy classes based on the domain entities returned by the domain service operation.Each of these client-side type are derived from the entity base type which has change tracking, validation, data binding, and updating capabilities.Both entity and entity set implement INotifyPropertyChanged, so just like the load operation object we can bind to our entities even before the data has finished loading from he server and then the UI gets notified when the operation is complete.
  7. Let’s take a look at the query proxy that is returned by the query factory method that gets generated by the tooling at build time. Remember, these query proxies are the ones we passed the Load method to invoke the corresponding server side operation.There type is EntityQuery&lt;T&gt;. Now before passing an entity query to the load method, we can actually extend it on the client. We mentioned that the EntityQuery class encapsulates information about the server-side query to invoke. That includes the query name and parameter information. EntityQuery also exposes a query property that can store an Iqueryable client-side query that we apply before invoking load.The entity query class has the capability of taking a client-side Linq query, store it and ultimately send that query across the network through the call stack so that it can be applied on the server.EntityQuery actually acts like an Iqueryable object on the client, and this capability is provided to it by the EntityQueryable extension class. Its extension methods allow us to apply a few specific Linq operators such as … and all this on the client.What this means is that we can filter and shape our query before it is passed on to he server.When the server call is made, along with the server-side name and parameters, the client-side Iqueryable is serialized and transmitted on the wire. The query sent to the DAL then combines both the server part and the client part of our request.This is a powerful part of Ria services as it allows us to shape the data, if we wish to, as close to the client as possible. Even though we can shape the data on the client, execution takes place on the server so we avoid the common pattern of having to haul back heavy loads of data only to discard large amounts of that data through pure client-side filtering.This is an important aspect of the framework as it provides the base capabilities for things such as the domain data source control.As we’ll see later in this course, using the domain data source control we can filter, sort, group and page data in a very simple and powerful way, and these features are enabled by this end-to-end query design that is part of the Ria services framework.
  8. Ria services allows us to retrieve object trees containing related entities in our queries. This simplifies classic scenarios such as master-detail scenarios and in general allows us to retrieve related objects together with the root object.There are actually several types of relationships that are facilitated by the framework including more complex ones such as composition relationships that exist between an order and its line items, and inheritance items. We are going to limit the talk to a basic association relationship that exist between two entity types.To enable the client to retrieve related entity types we need to take a couple of steps.First we need to annotate the server side entity types with the include attribute. If the entity types are generated automatically in our project, for example if we use EF or L2S as our data layer, we can do the attribute annotation in a metadata class that is associated with the root type instead of directly in the root type definition.The second thing we need to do is to explicitly include the related entities with the root entities and the results of our query operation in the service. Typically we do this using the Linq operator. As a result, the query operation will return an object tree that contains related entities along with the query and root entities.Once we build the project, the object tree becomes available on the client. The client’s entity proxy now has new properties that return the related entities that were specified on the server and these properties are annotated with the association attribute on the client that allows us to traverse the tree and access related properties client side.
  9. Now that we’ve looked at how to create and send queries from our Silverlight client to our domain service, let’s take a quick look at what happens behind the scenes.There are actually a slew of classes that participate in the query call on both sides of the network. On the client side, the domain context is agnostic of the communication stack. It uses a sub-class of domain client to set up the actual asynchronous call through the WCF pipeline. By default, it is the Web Domain Client that is used which knows how to create a WCF client channel using a channel factory and a service contract that was copied to the domain context at build time.On the server side an http module intercepts the query call from the client and dynamically creates an in-memory svc file.The in-memory svc file is based on the service contract that is shared with the client.In a previous step, the contract was generated by our domain service by a domain service host which changed the query operation return type from the one we specified in the domain service to a QueryResult&lt;T&gt; that contains additional information besides the result of the query.The domain service host also hosts the service and by default a binary encoded REST type endpoint is exposed