SB2055
SB2055

Reputation: 12862

Overriding DbContext get; set;

I have a DbSet<Photo> that I would like to use as a proxy to actual objects:

   public DbSet<Photo> Photos {
        get { return (DbSet<Photo>)DbPhotos.Where(s => !s.ToDelete); }
        set; // compilation error
    }

For some reason, set is unhappy saying Accessor must declare a body.

How do I implement the default set behavior while overriding the get?

Upvotes: 1

Views: 684

Answers (1)

Eric Sondergard
Eric Sondergard

Reputation: 605

You just need the braces.

public DbSet<Photo> Photos {
    get { return (DbSet<Photo>)DbPhotos.Where(s => !s.ToDelete); }
    set {}
}

As another commenter said, as soon as you give either get or set a body, the property is no longer an auto-property. So the syntax won't allow you to treat it as such.

Upvotes: 1

Related Questions