|
OK, so I've worked with Winforms and Webforms for 20 years.
But now I've been thrown into building a Silverlight 4 application from scratch without ANY previous training. So please bear with me if I ask some questions here that seems stupid to people who have worked a lot with Silverlight before.
My first worry is: Do you really have to use WCF/Entity Framework services to access data from a Silverlight app. Can't you use the traditional ADO.Net objects (SqlDataConnection, SqlCommand, SqlDataReader etc) and access the SQL server directly like you can from a Webforms app?
The reason I ask is that my few tests have shown me that compared to a Webapp with ADO.Net data access, WCF and Entity Framework services are painfully slow. And since I know already from the specs that we need the performance to be absolutely optimal, I would prefer to do it the traditional way.
However, when I choose add reference in my Silverlight project and want to add System.Data.SqlClient, it's not there. That makes me wonder if it's not possible to use it.
????
TIA!
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
You're mixing things up a bit...
First, remember that a Silverlight application runs on the client side, not the server. The client uses WCF to communicate with a server-side process, and the server can use Entity Framework or ADO.Net to communicate with the database.
WCF = Communication framework, to send messages between the client and server (Or other things)
Entity Framework = A way to map database objects into CLR objects, to simplify data access... Basically a wrapper around ADO.NET.
|
|
|
|
|
Ian Shlasko wrote: You're mixing things up a bit...
I might be - as mentioned, this is a first for me. I thought the silverlight app was rendered from the server as is the case with a normal webapp. If it physically runs on the client, then I can (to a certain point) understand my mixup.
But then again: If I install a winform app on the client machine, then I can access a remote db directly without WCF, as long as I know the correct query string. Why isn't that possible in Silverlight?
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
Johnny J. wrote: But then again: If I install a winform app on the client machine, then I can access a remote db directly without WCF, as long as I know the correct query string. Why isn't that possible in Silverlight?
You CAN have a Silverlight app go straight to the database, with the right security permissions and open ports on your network, though you're not really supposed to. Silverlight apps are supposed to access data by communicating with a server application, not by going directly to a database server.
So in short, the standard way to do it is:
Client-side SL App --[WCF]--> Server Application --[ADO/EF]--> Database
But if you cut out the server application and open your database to outside connections, you CAN do:
Client-side SL App --[ADO/EF]--> Database
EDIT: Ok, actually, I'm wrong about being able to do it that way... Silverlight isn't designed to go straight to a database at all...
http://forums.silverlight.net/forums/p/1350/3283.aspx[^]
|
|
|
|
|
Damn, damn, damn...
OK; thanks anyway. That does, however, make me wonder about whether or not it's worth creating the app in Silverlight...
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
Depends on what you're trying to do... Right tool for the right job, and all that.
If you need it to be in a browser, you can have the Silverlight client query through a server app, go back to WebForms and do it server-side, or use a different platform entirely.
If being in a browser isn't really necessary, you can get all the power of Silverlight in a full-fledged WPF application (WPF is a superset of Silverlight), which can go straight to the database and do just about anything else.
|
|
|
|
|
Johnny J. wrote: O.Net objects (SqlDataConnection, SqlCommand, SqlDataReader etc) and access the SQL server directly like you can from a Webforms app?
We cannot access Ado.net objects directly from Silverlight.
Nor can you add the SQLClient as these don't exist with Silverlight.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
i am not a fan of wizards , i always do my database work myself. You said you have been writing software for 20 years and that means you have probably heard of the N-Tier architecture.
As an N-Tier Architecture evangelist, i am writing Silverlight applications and i am using that architecture. i have a BLL service and a DAL service, the DAL service with be exactly what you normally have ADO.NET and the BLL will be just consuming the public functions of the DAL and the Silverlight will consume the BLL functions like wise.
This has no performance problems and this is fast as ever and i have not experienced any problems. Silverlight does not support ado.net directly, this is because it runs on the client side. I am writing a series of articles on the N-Tier architecture in Silverlight. Check this for continuity of the subject
http://www.dotnetfunda.com/articles/article1154-building-an-ntier-architecture-application-in-silverlight-4-part-i-.aspx[^]
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
That does indeed seem like the best solution, but it still involves services - not direct db access, which I would have preferred...
I still don't see why a Silverlight app running on the client can't access a db directly using ado when basically all other types can (winforms, webforms and even WCF apps I'm told in another post in this thread)... Bummer. But my guess is that it's done that way to keep the size of the runtime to an absolute minimum.
I'll have a look at your article, though, and I think I'll be going with this solution in the end (if I don't decide against Silverlight all together).
Beidh ceol, caint agus craic againn - Seán Bán Breathnach ----- Don't tell my folks I'm a computer programmer - They think I'm a piano player in a cat house... ----- Da mihi sis crustum Etruscum cum omnibus in eo! ----- Everybody is ignorant, only on different subjects - Will Rogers, 1924
|
|
|
|
|
Silverlight does not support all the protocols that WCF have, so to create a WCF service that can be used by Silverlight , you need to use BasicHTTP. So if you look at your web forms , you will see that the controls have the "runatserver" property , that is why you could use direct ado.net.
But in silverlight everything is fully on the client side. the nice thing about silverlight comparing it to win-forms and asp.net is that there are other things that you don't need to worry about , things like the post back , cross browser compatibility and it can run as a web app and as a win form like app(Out-of browser). my java-script skills are not that good that is why i prefer to place a control at a certain location of a form and expect to find it there when i run my app. its a matter of preference.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
I haven't seen this answer, so here's my attempt.
I'm not a Silverlight expert either, but I think Silverlight cannot access ADO.Net directly, because it is an application running ijn Internet Explorer, which is more or less a sandbox limiting possebilities. The reason why Asp.Net or WCF can access the database is because both run on the server (ASP.net does little more then generating text which the browser interprets as HTML).
in short, I think Silverlight is limited here because it runs inside the browser. Possibly there is a workaround...
V.
|
|
|
|
|
Hello,
I have a listbox of "users", when one is selected I want to display two listboxes: one containing the "reports" associated to the user, the other one the "other" reports. And buttons to move reports between the two listboxes. Very common scenario.
Users and reports are stored in a database accessed via ADO.NET. I have the following tables:
User: ReportingUser varchar(20) primary key
Reporting: ReportingCode varchar(20) primary key, ReportingName varchar(20)
ReportingUser: ReportingUser varchar(20), ReportingCode varchar(20)
I imported the tables in designer and added two Relations:
User_ReportingUser: ReportingUser.ReportingUser *->1 User.ReportingUser
FK_Reporting_ReportingUser: ReportingUser.ReportingCode *->1 Reporting.ReportingCode
The first relation is what my window edits. The second if for fishing the report name and display that instead of the report code.
I have the following XAML:
<ListBox Name="listBoxUsers" IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding}" DisplayMemberPath="ReportingUser" />
<ListBox Grid.Row="1" Name="listBoxSelectedReporting" ItemsSource="{Binding User_ReportingUser}"
DisplayMemberPath="Row.ReportingRow.ReportingName" />
...and Window_Loaded handler:
userAdapter = new UserTableAdapter();
reportingUserAdapter = new ReportingUserTableAdapter();
reportingTableAdapter = new ReportingTableAdapter();
dataset = new DNLMHDataSet();
userAdapter.Fill(dataset.User);
reportingTableAdapter.Fill(dataset.Reporting);
reportingUserAdapter.Fill(dataset.ReportingUser);
listBoxUsers.DataContext = dataset.User;
listBoxSelectedReporting.DataContext = dataset.User;
It's amazing to see that this suffices to give me master/detail behavior. My first question is: why does this work? Is there a compact explanation of this somewhere ?
I googled around and did find information, e.g. about IsSynchronizedWithCurrentItem, but it's not enough to enlighten me. Where is the "current item" stored ? In listBoxUsers ? How is the other listbox aware that the current item has changed ? The "content" of the User_ReportingUser Relation is parameterized by the currently selected user. How does the ItemsSource of the Report listbox know which user is current ? What's the activity diagram ?
Also, now I would like to implement the reports that are not selected for the current user. First I tried to create a query for that but the designer only allows SQL code that returns a single value. So I created a TableAdapter with the following SQL:
SELECT ReportingCode, ReportingName
FROM Reporting AS r
WHERE (NOT EXISTS (
SELECT ReportingCode
FROM ReportingUser AS u
WHERE(ReportingCode = r.ReportingCode) AND (ReportingUser = @ReportingUser)))
Here again the "content" of the table is parameterized by the same ReportingUser. How can I make the listbox for the non-selected reports coordinate automagically with the User master control ?
|
|
|
|
|
Hello,
How to bind List of objects in the button's CommandParameter in Xaml.
Thanks in adv..
|
|
|
|
|
Without looking at your code it is impossible to tell. But you could try relative binding or element name binding. These would be able to pass the collection of objects to your view model code.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
In silverlight, drawing a line, if zooming in it,the polyline will be deformation,a moving line will appear.
You can use bingmap for example.
MapPolyline line = new MapPolyline();
line.Stroke = new SolidColorBrush( Colors.Brown );
line.StrokeThickness = 3;
line.Locations = new LocationCollection();
double lon = 114.219340787406, lat = 23.0518068854053;
for ( int i = 0 ; i < 100 ; i++ )
{
int k = 1;
if ( i % 2 == 0 )
{
k = -1;
}
Location location = new Location( lat + k * 0.03, lon + 0.02 * i );
line.Locations.Add( location );
}
this.myMapLayer.Children.Add( line );
When you move the map amplifier to level 18th , moves to the line polyline, it will appear a line. And this line will move where map change.
How to solve this problem.
|
|
|
|
|
(Code below)
I create 200 RichTextBoxes into a collection on form load, so that I can populate a grid with them when the form is clicked.
When you click the form, it populates TestGrid with the 200 RichTextBoxes, one per row.
That part works fine, but whenever I change anything about the RichTextBoxes, like Background brush, or text, the memory just keeps on growing, each time I populate grid. I'm not ADDING text, it's the same text, every time. Nothing changes at all between grid refills.
Please, I implore you to copy this XAML and code to a new WPF project, and click on the form repeatedly, as you monitor task manager.
It's even worse if you change more properties other than text - like it can get to be 10 MB mem usage growth per refill.
I've looked on the web, to no avail. Makes no ******* sense.
WPF is great, but:
I've read from a lot of angry people on web about WPF memory probs. None of them talked about this scenario, though, unfortunately.
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ScrollViewer HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="ScrollViewer1">
<Grid Name="TestGrid">
</Grid>
</ScrollViewer>
</Grid>
</Window>
Imports System.Windows.Documents
Class MainWindow
Dim Riches As New Collection
Dim WorkRange As TextRange
Private Sub MainWindow_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
'HERE I'M FILLING THE RICHES COLLECTION WITH 200 RICHTEXTBOXES
Dim RichRange As Long, NewRich As RichTextBox
For RichRange = 1 To 200
NewRich = New RichTextBox
Riches.Add(NewRich)
Next
End Sub
Private Sub MainWindow_PreviewMouseDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles Me.PreviewMouseDown
Me.Title = "Start"
With TestGrid
.RowDefinitions.Clear()
.Children.Clear()
Dim RowRange As Long
For RowRange = 1 To 200
.RowDefinitions.Add(New RowDefinition)
Dim HeaderCell As RichTextBox
HeaderCell = Riches(RowRange)
With HeaderCell
WorkRange = New TextRange(.Document.ContentStart, .Document.ContentEnd)
WorkRange.Text = "Poo " & CStr(RowRange)
End With
.Children.Add(HeaderCell)
.SetRow(HeaderCell, RowRange - 1)
.SetColumn(HeaderCell, 0)
Next
End With
GC.Collect()
Me.Title = "Stop"
End Sub
End Class
If you're going to help me out and test this yourself, you can try commentizing the 2 lines of code that changes the text:
WorkRange = New TextRange(.Document.ContentStart, .Document.ContentEnd)
WorkRange.Text = "Poo " & CStr(RowRange)
By removing those two lines, no more memory growth will be visible in task manager.
Thanks a bunch!
|
|
|
|
|
Hello To All,
I am new to MVVM with Silverlight.
MyTestView --> View (Button, Grid)
MyTestViewModel --> ViewModel (WCF Service Methods)
In my button call I have assigned the DataContext. I have to fill grid with the data that have been returned from the service call in the same click event in the View's code behind.
Any help regarding this will be greatly appreciated..
Thanks in adv...
|
|
|
|
|
As in your other post, you are misunderstanding MVVM. All your code belongs in the ViewModel, not in the code behind (there are a few exceptions). You should not be assigning DataContext in button handlers. It should be set once using something like the view locator pattern. Everything that the View gets from the ViewModel is done with data binding, not code in the code behind.
|
|
|
|
|
Hi..
Thanks for the reply.
But I have situation for getting search criteria from the page and perform the operation in the button click event based on passing the search criteria to the view model.
So, How can I get view's control value in the viewmodel?
Can u pls give a hint about how to overcome such type of situations?
Thanks..
|
|
|
|
|
The search criteria should be bound to a property on the VM. You then have the data in the VM, responding to the event (click the search or the key up/down) need to be handled.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Set the view's datacontext to the view model.
You could then apply commands to handle the button command click in the view model.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hello to All,
Can anyone can help me get data from the ViewModel(DataContext of the page) in Page's Code behind using MVVM architecture.
Thanks in Adv..
|
|
|
|
|
this.LayoutRoot.DataContext
This assumes the layoutroot has the data context assigned (otherwise just this.datacontext). You will also need to cast the datacontext back to your viewmodel
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You should be setting the Datacontext of the page to the viewmodel somewhere if you are implementing MVVM correctly.
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
One of the aspects of MVVM is that you don't have any code behind. The only thing thats "allowed" in the code behind is manipulating visuals. The fact that you want to interact with the ViewModel from the code behind is definitely wrong.
|
|
|
|
|