You are here: Home » LINQ4SP – Delete a list item

LINQ4SP – Delete a list item

Posted by aghy
No Comments »

OK, let's play with LINQ4SP again.

You can download Beta1, write a simple query, create a new list item and lookup fields. In the next part I'll show you how to delete an item from a list:

        [TestMethod]        public void DeleteCreatedItems()        {            using (AwContext context = new AwContext())            {                var q = from subCategory in context.ProductSubcategory                        where subCategory.Title == "new sub category"                        select subCategory;

                foreach (ProductSubcategory psubcat in q) psubcat.DeleteOnSubmit();

                var p = from product in context.Product                        where product.ProductNumber == "AA" ||                            product.ProductNumber == "Double test" ||                            product.ProductNumber == "Date test"                        select product;                foreach (Product prod in p) prod.DeleteOnSubmit();

                var z = from pc in context.ProductCategory                        where pc.Title == "new product category"                        select pc;                foreach (ProductCategory prodcat in z) prodcat.DeleteOnSubmit();

                context.Submit();            }        }

Your email is never shared.
Required fields are marked *




Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>