RIA服务 - 无数据库?
问题描述:
Helo!RIA服务 - 无数据库?
我需要编写一个RIA服务来从Silverlight 3.0应用程序调用Java webservices。 我测试的东西是如何工作的,在我的Web应用程序我有有2个属性(INT ID,字符串文本)一类迈德特:
namespace SilverlightApplication1.Web
{
public class MyData
{
[Key]
public int ID { get; set; }
public string Text { get; set; }
}
}
然后我写了简单的DomainService:
[EnableClientAccess()]
public class MyService : DomainService
{
public IQueryable<MyData> GetMyData(string Url)
{
// here I will call my WebService
List<MyData> result = new List<MyData>();
result.Add(new MyData { ID = 1, Text = Url });
return result.AsQueryable();
}
}
}
我怎样才能将数据存入我的SL应用程序?现在我有这样的:
命名空间SilverlightApplication1 { 公共部分类的MainPage:用户控件 { 公众的MainPage(){ 在InitializeComponent (); MyContext context = new MyContext(); }} }
我打电话和负载,但nothink worsk(例外情况,或空)...
我不得不调用注解,但是迈德特不TEntity,我不能使用字符串或其它简单类型以及...:/ 我正在阅读和阅读帖子,没有什么作品像它应该..
任何帮助将非常感激。
谢谢!
答
您的代码在服务器上看起来不错。您将需要将上下文移动到MainPage构造函数之外,并向您的加载操作添加回调。另外请确保使用System.ServiceModel.DomainServices.Client添加到页面(用于LoadOperation)。
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using System.Windows.Controls;
using SilverlightApplication1.Web;
namespace SilverlightApplication1
{
public partial class MainPage : UserControl
{
MyContext context = new MyContext();
public MainPage()
{
InitializeComponent();
context.Load(context.GetMyDataQuery("url"), loadCallback, null);
}
void loadCallback(LoadOperation op)
{
MyData d = context.MyDatas.First();
}
}
}