在这个过程中,我们直接使用.NET RIA Services为你生成的客户端版本数据处理类了!很爽吧?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RiaServices_1.Web;
namespace RiaServices_1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
RdChat_DomainContext context = new RdChat_DomainContext();
dataGrid.ItemsSource = context.Messages;
context.LoadMessages();
}
private void btnSend_Click(object sender, RoutedEventArgs e)
{
Messages msg=new Messages();
msg.Body=txtMsg.Text;
msg.Name="匿名用户";
msg.PartitionKey = Guid.NewGuid().ToString();
msg.RowKey = "slChat";
msg.Timestamp = DateTime.Now;
RdChat_DomainContext context = new RdChat_DomainContext();
context.Messages.Add(msg);
context.SubmitChanges();
dataGrid.ItemsSource = context.Messages;
context.LoadMessages();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RiaServices_1.Web;
namespace RiaServices_1
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
RdChat_DomainContext context = new RdChat_DomainContext();
dataGrid.ItemsSource = context.Messages;
context.LoadMessages();
}
private void btnSend_Click(object sender, RoutedEventArgs e)
{
Messages msg=new Messages();
msg.Body=txtMsg.Text;
msg.Name="匿名用户";
msg.PartitionKey = Guid.NewGuid().ToString();
msg.RowKey = "slChat";
msg.Timestamp = DateTime.Now;
RdChat_DomainContext context = new RdChat_DomainContext();
context.Messages.Add(msg);
context.SubmitChanges();
dataGrid.ItemsSource = context.Messages;
context.LoadMessages();
}
}
}
怎样?非常方便吧?其实这只是一个非常简易的实例而已, .NET RIA Services还包括了许许多多强大的功能,包括metadata,shared code等等等等,请感兴趣的读者自行阅读SDK吧,那是一件非常享受的事情。