Dotneteers.net
All for .net, .net for all!

LINQ4SP - How to create a new item with a lookup to another list?

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();
.csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; } So, how do you like it?...

Posted May 20 2008, 11:44 PM by aghy

Add a Comment

(required)  
(optional)
(required)  
Remember Me?