Silverlight 2 is released. Achieving a database connectivity with the silverlight through a Ado.Net data service seems quite
complicated while trying initially. I have tried a lot and at last trie to achive the connectivity. I have followed the
following steps to achive this.
1. Create a blank new silverlight project with Asp.net website enabled.
2. Add a new entity model (SchoolModel) referring your database for example say School Database. For this a new schoolEntity
will be generated.
3. Add a new Ado.Net data service say ScDataSRC.svc. There specify the context name of your service as SchoolEntity.
Public Class ScdDataSrc
Inherits DataService(Of SchoolEntities1)
4.Set the web properties of the webapplication so that it runs in a standrad port instead of dynamic configuration.
5.Now test the service by setting the service as the startup page ScDataSrc.svc . you will get a url like
http://localhost:2031/ScdDataSrc.svc/
6.Now in the silverligh project just refer this service.
Take for example we are going to fill a datagrid in the silverlight page. Add them in the XAML.
7. Import the following in the Silverlight application
Imports Microsoft
Imports System.Data.Services.Client
Imports SilverlightApplication6.SchoolRef
8. Silverlight deals the data in an Asynchronous way. So we have to handle them in th following way
1. Create a instance for the context
Dim ctx As New SchoolRef.SchoolEntities(New Uri("http://localhost:2031/ScdDataSrc.svc/"))
2. form the linq query that needs to fetch the data.
Dim pr = From c As Course In ctx.Course _
Select c
3. Now typecast the query to dataservice query and assign a asynchronous method to that . This asynhronous
method takes care of fetching the data from service .
Dim prdquery As DataServiceQuery(Of Course) = DirectCast(pr, DataServiceQuery(Of Course))
prdquery.BeginExecute(New AsyncCallback(AddressOf onLoadComplete), prdquery)
Public Sub onLoadComplete(ByVal result As IAsyncResult)
Dim results As IEnumerable(Of Course)
results = DirectCast(result.AsyncState, DataServiceQuery(Of Course)).EndExecute(result)
Me.MyCombo.DataContext = results.ToList
4. Bind the objects inside the Async methods.
complicated while trying initially. I have tried a lot and at last trie to achive the connectivity. I have followed the
following steps to achive this.
1. Create a blank new silverlight project with Asp.net website enabled.
2. Add a new entity model (SchoolModel) referring your database for example say School Database. For this a new schoolEntity
will be generated.
3. Add a new Ado.Net data service say ScDataSRC.svc. There specify the context name of your service as SchoolEntity.
Public Class ScdDataSrc
Inherits DataService(Of SchoolEntities1)
4.Set the web properties of the webapplication so that it runs in a standrad port instead of dynamic configuration.
5.Now test the service by setting the service as the startup page ScDataSrc.svc . you will get a url like
http://localhost:2031/ScdDataSrc.svc/
6.Now in the silverligh project just refer this service.
Take for example we are going to fill a datagrid in the silverlight page. Add them in the XAML.
7. Import the following in the Silverlight application
Imports Microsoft
Imports System.Data.Services.Client
Imports SilverlightApplication6.SchoolRef
8. Silverlight deals the data in an Asynchronous way. So we have to handle them in th following way
1. Create a instance for the context
Dim ctx As New SchoolRef.SchoolEntities(New Uri("http://localhost:2031/ScdDataSrc.svc/"))
2. form the linq query that needs to fetch the data.
Dim pr = From c As Course In ctx.Course _
Select c
3. Now typecast the query to dataservice query and assign a asynchronous method to that . This asynhronous
method takes care of fetching the data from service .
Dim prdquery As DataServiceQuery(Of Course) = DirectCast(pr, DataServiceQuery(Of Course))
prdquery.BeginExecute(New AsyncCallback(AddressOf onLoadComplete), prdquery)
Public Sub onLoadComplete(ByVal result As IAsyncResult)
Dim results As IEnumerable(Of Course)
results = DirectCast(result.AsyncState, DataServiceQuery(Of Course)).EndExecute(result)
Me.MyCombo.DataContext = results.ToList
4. Bind the objects inside the Async methods.
0 comments:
Post a Comment