Ria DomainService input parameter weirdness, Delete is special?

In the RIA domain service, I added some useful features. For example, we have ...

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

Now this function has its problems if the identifier is not real, but now it allows you to use the table. The important thing is that the function is compiled and executed.

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); } } 

Throws 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 fact is that I can understand that the (string id) parameter is not suitable for EF, but why is this normal in one case and not in another?

Entrance is welcome :)

+4
source share
1 answer

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

Request methods from other hands do not accept entities as parameters. Therefore, the string is the ok parameter for the get request method.

In your case, you want DeleteCmsDealer to accept CmdDealer. You can still find the db inside your method and delete the instance you downloaded, rather than attach / remove the instance if required.

Hope this helps.

+10
source

All Articles