执行 SQL 查询 WCF RIA Silverlight
我创建了一个数据库,并将其与 Silverlight 应用程序中的 DomainService 链接。现在我希望能够使用该服务执行某些操作,例如注册、登录等。
我怎样才能做到这一点。我在服务中创建了预设方法,例如InsertUser,但它只需要一个参数,所以我不确定它是如何工作的。在元数据中,我有所有字段等。
任何人都可以在这里帮助我。
谢谢。
public IQueryable<User> GetUsers()
{
return this.ObjectContext.Users;
}
public void InsertUser(User user)
{
if ((user.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(user, EntityState.Added);
}
else
{
this.ObjectContext.Users.AddObject(user);
}
}
为了检索我使用的用户(作为 TBohnen.jnr 代码的基础):
UserContext _userContext = new UserContext();
public MainPage()
{
InitializeComponent();
LoadOperation loGetUsers = _userContext.Load(_userContext.GetUsersQuery());
loGetUsers.Completed += new EventHandler(loGetUsers_Completed);
}
void loGetUsers_Completed(object sender, EventArgs e)
{
LoadOperation<Web.User> lo = (LoadOperation<Web.User>)sender;
var user = _userContext.Users;
MessageBox.Show(user.ToString());
}
I have created a database, linked it with DomainService's within my Silverlight Application. Now I want to be able to perform certain actions, such as Registration, Login etc. by using the service.
How would I be able to do this. I have preset methods created in the service, e.g. InsertUser but it only requires one parameter, so I'm not sure how it works. In the metadata I have all fields etc.
Can anyone help me out here.
Thanks.
public IQueryable<User> GetUsers()
{
return this.ObjectContext.Users;
}
public void InsertUser(User user)
{
if ((user.EntityState != EntityState.Detached))
{
this.ObjectContext.ObjectStateManager.ChangeObjectState(user, EntityState.Added);
}
else
{
this.ObjectContext.Users.AddObject(user);
}
}
For retrieving User I have used (as a base from TBohnen.jnr code):
UserContext _userContext = new UserContext();
public MainPage()
{
InitializeComponent();
LoadOperation loGetUsers = _userContext.Load(_userContext.GetUsersQuery());
loGetUsers.Completed += new EventHandler(loGetUsers_Completed);
}
void loGetUsers_Completed(object sender, EventArgs e)
{
LoadOperation<Web.User> lo = (LoadOperation<Web.User>)sender;
var user = _userContext.Users;
MessageBox.Show(user.ToString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是添加一个新用户:
检索现有用户:
这将触发一个异步调用,获取所有用户并将其添加到 DomainContext,您将能够通过 dc.User 访问它
This is to add a new user:
To retrieve your existing users:
This will trigger an async call that get's all the users and will add it to the DomainContext and you will be able to access it through dc.User