Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a collection of Entities to .NET RIA Data Service?

Tags:

Is it possible to pass a collection of objects to a RIA Data Service query? I have no issues sending an Entity, an Int or an array of primitive types, but as soon as i declare a method like this

public void GetLessonsConflicts(Lesson[] lessons)
{
}

i get a compilation error

" Operation named 'GetLessonsConflicts' does not conform to the required signature. Parameter types must be an entity type or one of the predefined serializable types"

I am just trying to do some validation on the server side before i save the data. I've tried List, IEnumerable etc.

Thanks

like image 742
Vitalik Avatar asked Dec 01 '09 05:12

Vitalik


1 Answers

I think the problem is actually the lack of a return value. As I understand it, you can identify DomainOperations by convention or by attribute. You're not showing an attribute so RIA will be trying to match it by convention.

For example, by convention, an insert method must:

  • have Insert, Add or Create as the method name prefix, e.g. InsertEmployee
  • match the signature public void name(Entity e);

a query method must:

  • be public
  • return IEnumerable, IQueryable or T (where T is an entity).

a custom domain operation must

  • be public
  • return void
  • have an Entity as the first parameter.

EDIT: See Rami A's comment below. I believe this was true at the time but I'm not currently working with this technology so I'm not current enough on it to update this answer other than to note that it may be incorrect.

Or you can use Attributes such as [Insert],[Delete],[Update],[Query],[Custom]. From my docs, all the attributes do is remove the requirement for the name convention - it's not clear from them, to me, what the [Query] and [Custom] attributes achieve.

As well as DomainOperations, you can define ServiceOperations (using the [ServiceOperation] attribute) and InvokeOperations.

This article might help (although I think it's a bit out of date).

like image 193
serialhobbyist Avatar answered Oct 12 '22 23:10

serialhobbyist