Click here to Skip to main content
15,921,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,
Entity Framework 4.0 reference tables not showing? How to delete the records from these tables using Entity FrameWork Model.

Thanks And Regards

Mohit Sharma
Posted

1 solution

assuming that the entity == Entities
the model is linked with his "using"
and you want to delete a record of the
"Record" table with id = 1
you can use


C#
using (Entities entitiesContext = new Entities())
    {
        var e = from x in entitiesContext.Records
                where x.Id = 1
                select x;
        Record record = e.FirstOrDefault();
        entitiesContext.Records.DeleteObject(record);
        entitiesContext.SaveChanges();
    }





if the record is not only one but a lot, you have to use a foreach loop with the DeleteObject method

and outside of the loop you can save changes
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900