Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ria DomainService input parameter weirdness, Delete is special?

In a RIA Domain service I have added some utility functions. For instance we have...

public virtual CmsDealer GetCmsDealerById(string id)
{
    return this.Context.CmsDealerSet
        .Include("CmsItemState")
        .FirstOrDefault(p => p.Id == id);
}

Now that function has it's own issues if the id is nonexistant, but lets table that for now. The important thing is that function compiles and executes.

However a similar function...

public virtual void DeleteCmsDealerById(string id)
{
    var dealer = this.Context.CmsDealerSet
        .FirstOrDefault(d => d.Id == id);

    if (dealer != null)
    {
        DeleteCmsDealer(dealer);
    }
}

Tosses a compile time error.

*Parameter 'id' of domain method 'DeleteCmsDealerById' must be an entity type exposed by the DomainService, either directly via a query operation, or indirectly via an included association.*

The thing is, I can understand that the (string id) param is not accewptable to EF, but why is it OK in one case and not another?

Input welcome :)

like image 800
Samurai Ken Avatar asked Dec 29 '22 16:12

Samurai Ken


1 Answers

The convention is that delete methods have a signature that take an entity. A string is not an entity. A entity is a type that a) has a member with a [Key] and b) is a type returned by one of the query methods in the domain service.

Query methods on the other hands do not take entities as parameters. Hence string is an ok parameter for the get query method.

In your case you'll want DeleteCmsDealer to take in a CmdDealer. You can still look up the db inside your method and delete the instance you loaded, rather than attach/delete the instance passed in if that is required.

Hope that helps.

like image 67
Nikhil Kothari Avatar answered Feb 23 '23 21:02

Nikhil Kothari