tags:

views:

38

answers:

1

Hi -I have 2 entities -Offer and Share. Share stores the offers shared by users.

class Offer
    int IDOffer;
    bool Shared;
    (other properties)

class Share
    int IDOffer;
    int IDUser;

where Offer.IDOffer = Share.IDOffer, 1-to-1 (users may share an offer only once, or not at all).

I extended Offer with the Shared property -it's not in the database but in the entity.

Now I need to select Offers and set Offers.Shared based on the Share entity.

Could you point me the right way? I appreciate your help.

A: 

I don't believe these sort of properties are supported well in LINQ to SQL. It seems you should be able to write something like this:

void partial OnLoaded()
{
    this.Shared = !this.Share == null;
}

But I think this won't work because the OnLoaded method may execute before your entity is actually loaded. I recommend just comparing Share to null whenever you need this sort of idea expressed. Like this:

//Select all offers that are shared
var result  = from offer in Offers
              where !offer.share == null
              select offer;

Edit: Wrote the first version forgetting this is a one-to-one. Edited to work with EntityRefs.

Sorax