Hello,
I am writing a proof of concept (PoC) using the AdventureWorks database, Silverlight 4, RIA services and LLBLGen.
I can successfully query all employees like this on my domain service:
public IQueryable<EmployeeEntity> GetEmployeesByCount(int maxResults)
{
LinqMetaData metaData = new LinqMetaData();
var result = from employee in metaData.Employee
select employee;
if (maxResults > 0)
{
result = result.Take(maxResults);
}
return result;
}
Works perfectly in my grid. Next I try to update an entity. I update some values (say gender from M to F), then I call this on the client (Silverlight):
/// <summary>
/// Called when the edit command has completed.
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="Catel.MVVM.Services.UICompletedEventArgs"/> instance containing the event data.</param>
private void OnEditComplete(object sender, UICompletedEventArgs e)
{
if (e.Result ?? false)
{
_context.SubmitChanges();
}
else
{
_context.RejectChanges();
}
}
The _context is the same context I used to load the entities (this way):
private void LoadEmployees(int maxResults)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
var loadOperation = _context.Load(_context.GetEmployeesByCountQuery(maxResults));
loadOperation.Completed += (sender, e) =>
{
stopwatch.Stop();
LastLoadDuration = stopwatch.Elapsed;
var employees = _context.EmployeeEntities;
Employees = employees;
};
}
Then, when I submit the changes (_context.HasChanges is true), I get this exception (and the PK hasn't changed):
The field 'EmployeeId' is read-only and can't be changed. (ORMFieldIsReadonlyException).
Any idea why the service is trying to update the PK?
Thanks in advance!
Best regards,
Geert