开发者

RIA EF4 complex many to many filter

first of all sorry for my bad english.

I have a DB structure similar to that:

RIA EF4 complex many to many filter

Using RIA Services with EF4.1 what would be the best way to select only the cars that has some Characteristics?

On the Client the user can select multiple "Characteristic" and inform a Value. I then need to show all the Cars that has that Characteristics with that specific value (the "value" is saved on the CarCharacteristic table) (something like all "cars" (Car) that have "2" (CarCharacteristic) "doors" (Characteristic))

I would like to do this on the client but it seems it is not possible :(

To be able to filter this on the server, I need to send at least all the CharacteristicId of the selected Characteristics and the user informed value to each one.

Problem is that if I create a query with any complex (e.g MyClass[]) parameter I get the error:

Parameter 'x' of domain operation entry 'GetCarsByCharacteristic' must be one of the predefined serializ开发者_C百科able types

I think I am missing something obvious here because it can't be so hard...

How would be the right way to do this kind of thing?


First of all, since you want to send an array as a parameter of a query, you'll need to mark the query with HasSideEffects=true attribute, like so:

    [Query(HasSideEffects=true)]

Now you MIGHT be able to send your own class as a parameter (I'm not sure, I haven't checked yet), but you can definitely use a parameter of type Dictionary<Guid, int> where I assume Guid is the type you use for Ids, while int is the value.

Now you can filter the set by Ids and the values as needed.

EDIT: Also, you didn't mention using a DomainDataSource, so I'm guessing you're working with a DomainContext object. In this case, you can add the filtering client-side like so:

        ctx.Load(ctx.GetMyDataQuery().Where(entity => entity.Value = value && entity.CharacteristicId = characteristicId), false);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜