Hi everybody
I want to write a method to run in the server to generate, in batch, a set of entities from a "given base entity" as Pattern.
Basically i Have a given entity an through a cycle i create a set o new entities changing the key field.
From the client side I invoke the server method passing the “pattern entity”, de first number, last number and de Step.
the server creates new entities, adds them to the entimanager and calls the Savechanges method.
It Works well(the new entities are created in my sql server database), but , I
don’t know why the server method is called twice!!!
The SilverLight only calls it once!!!
Any tips would be apreciated
Thanks in advance
//--. Silver light Side
private void DoConfirmCommand(object iView)
{
Alojamento _alojamento;
_alojamento = Alojamento.Create(0);
_mgr.AddEntity(_alojamento);
string typeName = "Alojamentos.Models.RemoteServiceMethods, AlojamentosWeb";
string methodName = "GenerateAlojamentos";
Guid myInvokeGuid = System.Guid.NewGuid();
DoAsyncAction(() => { _mgr.InvokeServerMethodAsync(typeName, methodName, GotData, myInvokeGuid, _alojamento, InicialRecord, FinalRecord, Step); });
}
protected void DoAsyncAction(Action a)
{
a();
}
void GotData(InvokeServerMethodOperation e)
{
if (!e.Cancelled)
{
bool gerou = (bool)e.Result;
}
}
// ---- Server Side Method -------------------------
using System;
using System.Linq;
using IbEm = IdeaBlade.EntityModel;
using IdeaBlade.Core;
using IdeaBlade.EntityModel;
using System.Security.Principal;
using System.Collections.Generic;
namespace Alojamentos.Models
{
public class RemoteServiceMethods
{
[AllowRpc]
public static Object GenerateaAlojamentos(IPrincipal principal, EntityManager mgr, params Object[] args)
{
// Cast EntityManager to its more specialized type for this app
EntidadesAlojamentos DomainMgr = (EntidadesAlojamentos)mgr;
Alojamento alojamento = args[0] as Alojamento;
for (int i = (int)args[1]; i <= (int)args[2]; i += (int)args[3])
{
Alojamento newaloj = (Alojamento)((ICloneable)alojamento).Clone();
newaloj.intNumero = i;
DomainMgr.AddEntity(newaloj);
}
SaveResult result = DomainMgr.SaveChanges();
return result;
}
}