locked
Deleting of Many To Many relation problem. RRS feed

  • Question

  • Hi,

    I'm using NHibernate as custom datacontext.

    When I perform delete of many to many assotiation i've got an exception in GetResource method of datacontext.

    I wonder why ADO.NET Data Services tries to get entity which link is deleted using following query:

    {value(NHibernate.Linq.Query`1[Domain.News]).Where(element => (element.NewsID = 1)).SelectMany(element => Convert(element.Tags)).Where(element => (element.TagID = 1))} - this query is fail to execute in GetResource method, because NH have poor support of selectmany.

    News has many tags. Here I have deleted link on Tag from News.

    But I think that query should be simply Select tag by Id.
    Thursday, November 19, 2009 5:07 AM

Answers

  • I think the client sends a request something like this: DELETE /News(1)/$links/Tags(1) or maybe the other way round.

    For such a query, the server makes 2 calls to GetResource - one for /News(1) and one for /News(1)/Tags(1). To make sure that i understand your question correctly, you are saying why don't we just call for News(1) rather than /News(1)/Tags(1)?

    The reason why we do query for /News(1)/Tags(1) is so that we can make sure that there is such a tag related with news. Otherwise we need to depend on the provider to make sure that they need to track the relationship between two independently queried entities and fail on SaveChanges. This means we are making a lot of assumption about the providers and we were trying to make these assumptions as less as possible.

    Thanks
    Pratik


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Thursday, November 19, 2009 5:44 PM
    Moderator