views:

217

answers:

1

I'm extending an entities' partial class to have a method. How do I get a reference to the context that the entity is attached to (if any) to get more entities from the same context.

If that's not clear, basically the code I'm looking to write is along these lines (air code):

public void AssignSize(int width, int height)
{
    var size = (from s in this.context.Sizes
                where s.width == width && s.height == height
                select s).FirstOrDefault();

    ...
}

Nb: This doesn't work.

+3  A: 

You need to pass the context to this method, or, better yet, rather than pass in width and height, pass in the size object itself.

Andrew Peters
Point taken on the lameness of the example :o) So no way of doing it without passing the context in? That's a shame.
DeletedAccount
Consider this:var myEntity = new MyEntity();myEntity.AssignSize(1,2);This is just one problem with coupling an entity to a particular context.
Andrew Peters