RIA services tries to update primary key

Posts   
 
    
Posts: 69
Joined: 24-Jun-2008
# Posted on: 23-May-2011 15:39:13   

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

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 23-May-2011 16:02:45   

Please check this thread: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=19770

You'll need to use Adapter instead of SelfServicing.

Posts: 69
Joined: 24-Jun-2008
# Posted on: 23-May-2011 16:04:58   

Thanks for the fast reply. It's not what I wanted to hear, but at least I can solve the issue now.

Thanks.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 24-May-2011 09:30:43   

CatenaLogic wrote:

Thanks for the fast reply. It's not what I wanted to hear, but at least I can solve the issue now.

Thanks.

Yeah, it's really unfortunate. If it's really necessary (e.g. you already have a large Selfservicing using piece of code and you want to write a service for it), we could look into a setting which switches off the 'readonly check on pks', but we can't change it today just like that. As it happens during deserialization outside our service code, we can't work around that at the framework level inside the service code.

Frans Bouma | Lead developer LLBLGen Pro
Posts: 69
Joined: 24-Jun-2008
# Posted on: 24-May-2011 10:13:20   

The problem is that the RIA Services documentation (see http://www.llblgen.com/documentation/3.1/LLBLGen%20Pro%20RTF/Using%20the%20generated%20code/gencode_wcfriaservices.htm) talks about self-servicing. This gave me the idea that it was possible. You might want to put some kind of warning there.

For now, Adapter is fine. No need to do additional stuff. The only thing I couldn't find was actual documentation about the LLBLGenProDomainService. For example, it's abstract, and I have to implement the CreateTransaction and UpdateEntity support, but no idea if I really have to implement them.

For example, in adapter the StartTransaction does not return a transaction (so I can't use that in CreateTransaction).

Posts: 69
Joined: 24-Jun-2008
# Posted on: 24-May-2011 10:16:27   

Of course I have to change the DomainService to DomainService2 when changing to adapter. My fault!