- May
- 20
- 2008
LINQ4SP – How to create a new item with a lookup to another list?
Posted by aghy
No Comments »
Well, how do you like our solution to query a list or insert a new item to a list by LINQ4SP? What do you think about it?
What would you tell, if I show you a newer interesting thing? Are you ready? – OK, today surprise is how to insert a lookup reference to another list. See this short demo, or check a piece of code here:
// Create a new Category
ProductCategory pc = new ProductCategory()
{
Title = "new product category",
};
// Create a new Sub-Category item
ProductSubcategory pcat = new ProductSubcategory()
{
Title = "new sub category",
ProductCategory = pc // <<– WOW! This is a lookup to Categories…
};
// Submit our new Sub-Category
context.ProductCategory.InsertInSubmit(pc);
context.ProductSubcategory.InsertOnSubmit(pcat);
context.Submit();
So, how do you like it?…