Domanda

I have a winforms app with a detail form, datagridview, and bindingnavigator all bound to the same datasource. I'm using entity framework (database first). The user works with groups of records in the datagridview; hundreds but possibly thousands at a time. The bindingnavigator shows how many records are currently loaded into memory.

The details form is disabled until they hit an "Edit" button. Is there a practical way to limit the dbContext to a single record when they decide to edit? In my mind the dbcontext is tied to the datasource, which is bound to the controls.

Examples I have found such as msdn.microsoft.com/en-us/data/jj682076.aspx explain how to use dbcontext to select the *entire list of entities, bind them to a datagridview, and use context.SaveChanges() to update the database. I have yet to find a good example of how to limit the context to a single record when working with multiple records in winforms.

È stato utile?

Soluzione

you shouldn't be binding EF objects to a dbContext when simply loading for view purposes. The dbContext should *only be used when you need to perform your CRUD operations. The context should not be opened for long periods of time either.

You should post where you create your dbContext, you should be closing your context after loading your data.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top