In a Silverlight application I use a stored procedure to update a table of my data base.
ALTER PROCEDURE [dbo].[SP_ADD_MIS_MISSION]
(
@IdMission as int,
@IdVersion as smallint,
@LibMission as varchar (50)
)
AS
BEGIN
DECLARE @IDNEWVERSION as int = 1,
@IDNEWMISSION as int = @IdMission,
@supp as bit = 1
BEGIN
IF @IdMission != 0 AND @IdMission is not NULL
BEGIN
SELECT @IDNEWVERSION = MAX(IDVERSION)+1 FROM MIS_Mission where MIS_Mission.IdMission=@IdMission
Update MIS_Mission SET Suppression = @supp WHERE MIS_Mission.IdMission=@IdMission AND MIS_Mission.IdVersion=(@IDNEWVERSION-1)
END
ELSE
BEGIN
SET @IDNEWVERSION = 1
select @IDNEWMISSION = MAX(MIS_Mission.IdMission)+1 from MIS_Mission
if @IDNEWMISSION is NULL SET @IDNEWMISSION=1
END
Insert MIS_Mission ( IdMission,
IdVersion,
LibMission,
Suppression
)
values ( @IDNEWMISSION,
@IDNEWVERSION,
@LibMission,
@Suppression
)
SELECT @IDNEWMISSION
END
I added this code in my WCF RIA services to launch the stored procedure:
public void SetMission(MIS_Mission mis)
{
_entity.ADD_MIS_MISSION(mis.IdMission,mis.IdVersion,mis.LibMission);
}
And I added this code in my Silverlight application to update my database whith the value enter in my datagrid :
private void UpdateMission_Click(object sender, RoutedEventArgs e)
{
foreach(MIS_Mission mis in dG_Mission.ItemsSource)
{
var operation = _Context.SetMission(mis);
operation.Completed += (se, ev) =>
{
};
}
}
But when I finished to update my database, my context didn’t updat whith the new values of IdVersion, and my datagrid display the old versions of my missions.
How can I update my context without reload my datagrid?
I find a solution on this website : http://weblogs.asp.net/fredriknormen/archive/2009/11/24/refresh-the-cached-entityset-after-a-submitchanges-wcf-ria-services.aspx
My solution is like this:
This solution work fine for me but the refresh of the datagrid is a bit slow.
Thanks for your help
bye