在 Silverlight 中更新自定义数据上下文
因此,我在 SL 应用程序中动态地、以编程方式为不同屏幕设置单独的数据上下文。我这样做是因为需要在一个屏幕上显示来自不同数据库表的数据。
我的挑战是这样的:查询个人信息和近亲信息(不同的表)后,我需要将屏幕上所做的所有更新提交到相应的表。
我编写了一个自定义查询,通过自我加载(LINQ)获取数据,但是在设置屏幕的数据上下文后,如何提交所做的更改?
下面是查询代码
public PersonalInfoModel GetPersonalInfo(string email)
{
var PersonalInfo = (from p in DataContext.OFFLINEAPPLICANTs
where p.EMAIL_ADDRESS == email
select new PersonalInfoModel
{
AppEmail = p.EMAIL_ADDRESS,
FirstName = p.FIRSTNAME,
LastName = p.LASTNAME,
MiddleName = p.MIDDLENAME,
Denomination = p.RELIGIOUSAFF,
DateOfBirth = p.DOB,
AppliedDate = p.CREATEDDATE.Value,
Gender = p.GENDER,
TrnOrSsn = p.SSN_TRN,
Nis = p.NIS,
NationalCountry = p.Country.Country1,
NokEmail = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.email).FirstOrDefault(),
NokFax = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.fax).FirstOrDefault(),
NokFirstName = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.first_name).FirstOrDefault(),
NokLastName = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.last_name).FirstOrDefault(),
NokPhone1 = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.tel1).FirstOrDefault(),
NokPhone2 = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.tel2).FirstOrDefault(),
NokRelationship = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.relationship_id).FirstOrDefault(),
}).FirstOrDefault();
return PersonalInfo;
}
,在从父 SL 控件加载数据后,我将视图的数据上下文设置为从该查询返回的数据。
我如何提交更改或着手执行此操作?
顺便说一句,我正在使用 RIA 服务
So I dynamically and programatically set separate datacontexts for different screens in my SL app. I did this because there was data that needed to be displayed in one screen, coming from different Database tables.
My challenge is this: After querying personal information and next of kin information (different tables), I need to submit all updates made on the screen to the respective tables.
I wrote a custom query getting the data via Ego loading (LINQ), but How do I sbumit the changes made, after I set the datacontext of the screen already?
Here is the query code
public PersonalInfoModel GetPersonalInfo(string email)
{
var PersonalInfo = (from p in DataContext.OFFLINEAPPLICANTs
where p.EMAIL_ADDRESS == email
select new PersonalInfoModel
{
AppEmail = p.EMAIL_ADDRESS,
FirstName = p.FIRSTNAME,
LastName = p.LASTNAME,
MiddleName = p.MIDDLENAME,
Denomination = p.RELIGIOUSAFF,
DateOfBirth = p.DOB,
AppliedDate = p.CREATEDDATE.Value,
Gender = p.GENDER,
TrnOrSsn = p.SSN_TRN,
Nis = p.NIS,
NationalCountry = p.Country.Country1,
NokEmail = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.email).FirstOrDefault(),
NokFax = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.fax).FirstOrDefault(),
NokFirstName = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.first_name).FirstOrDefault(),
NokLastName = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.last_name).FirstOrDefault(),
NokPhone1 = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.tel1).FirstOrDefault(),
NokPhone2 = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.tel2).FirstOrDefault(),
NokRelationship = p.NEXT_OF_KINs.Where(q => q.email_address == p.EMAIL_ADDRESS)
.Select(q => q.relationship_id).FirstOrDefault(),
}).FirstOrDefault();
return PersonalInfo;
}
and after loading the data, from a parent SL control, I set the View's datacontext to the data returns from that query.
How do I submit the changes, or go about doing so?
I am using RIA Services btw
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我意识到不能那样做。相反,我必须调用包含相应数据的原始表并相应地更新字段并将更改提交到上下文。
Well I came to the realization that it cannot be done that way. I instead, had to recall the original tables housing the respective data and update the fields accordingly and submit the changes to the context.