How to write a class to retrieve IEnumerable objects in EF and C #

I am using C # asp.net 4 web forms and ef4.

In my code Following me, I use the code below several times to link and rebuild (for updating) the e GridView after insertion or other operations performed using EF objects.

Using a simple gridview.DataBind (); it doesn’t work because I call EF programmatically, so I thought of using a class to store in memory this code, which can create objects for my GridView and call it how much time I need in my code, avoiding redundancy.

IEnumerable<CmsContent> queryContents = 
    myCurrentSlot.CmsContents.Where(x => x.IsPublished == true);

uxManageContents.DataSource = queryContents;
uxManageContents.DataBind();

Can you help me write this class? Or do you know how to use the test method Refresh gridview after EF executes some commands? how to do it?

Remember that I use any data source web control for gridview, but I bind it programmatically.

+3
source share
1 answer

Use ObjectDataSource instead of codebehind.

+2
source

All Articles