Timothy Khouri - SingingEels.com

I subscribe to the "take it apart and rebuild it" approach to learning.

LINQ to SQL is My Hero!

I've just discovered something very beautiful in LINQ to SQL (which I already loved before seeing this). This is one of the most difficult problems to overcome using Microsoft SQL Server, and the solution that the LINQ team came up with is very clean and insightful.

It's a quick read: http://www.singingeels.com/Blogs/Nullable/2008/03/05/LINQ_to_SQL_is_My_Hero.aspx

Posted: Mar 05 2008, 06:37 PM by Nullable | with 3 comment(s)
Filed under: , ,

Comments

pbz said:

I would have posted on that site but they're too strict with their requirements to create an account.

My point would have been that with a little forethought and a better database design this should be achievable without a big hassle. Sounds to me like the author is not familiar enough with SQL (the query language) and jumped to the conclusion that it can't be done. There are very few things you can't do with SQL if you know it well enough.

# March 5, 2008 7:47 PM

Nullable said:

Actually, I'm more than just familiar enough with SQL... and I said that it can be done, but it's difficult.

So here's my challenge to you :) There is a stored procedure that returns a list of restaurants based on a users selection of categories... the user selected 15 out of the 100 available types... please, write an example stored procedure that would return the restaurants that are in any of the 15 selected categories.

Have fun!

# March 6, 2008 8:36 AM

Webys said:

I have a little problem I'm a beginner in LINQ to SQL and I've follow the tutorial from ScottGu's blog: weblogs.asp.net/.../linq-to-sql-part-5-binding-ui-using-the-asp-linqdatasource-control.aspx

All was ok I use VS 2008 (I've converted from VB.NET to C# , I use C#) but when I wish to put the code from App_Code in an sub dir like DAL or BLL (for extensibility of entities like products with partial clases) and generate again the dblm file I've receiving en error:

1. first in my BLL dir from App_Code:

  public partial class Product

   {

       partial void OnValidate(System.Data.Linq.ChangeAction action)

       {

           if (action == ChangeAction.Update && this.Discontinued == true && this.UnitsOnOrder > 0)

           {

               throw new ArgumentException("Record level can't be grather than 0 if Product is Discontinued");

           }

       }

}

and I've included the namespace : using DAL;

... but still error message is :No defining declaration found for implementing declaration of partial method 'Product.OnValidate(System.Data.Linq.ChangeAction)'

2  If i comment all BLL code from my extensibility partial class Product I receive an general error:

Could not load type 'NorthwindDataContext'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Could not load type 'NorthwindDataContext'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): Could not load type 'NorthwindDataContext'.]

  System.Web.Compilation.BuildManager.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) +565

  System.Web.UI.WebControls.LinqDataSourceView.get_ContextType() +68

[InvalidOperationException: Could not find the type specified in the ContextTypeName property of LinqDataSource 'CategoryLinqDS'.]

  System.Web.UI.WebControls.LinqDataSourceView.get_ContextType() +193

  System.Web.UI.WebControls.LinqDataSourceView.CreateContextAndTable() +458

  System.Web.UI.WebControls.LinqDataSourceView.EnsureContextAndTable(Boolean selecting) +39

  System.Web.UI.WebControls.LinqDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +421

  System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +92

  System.Web.UI.WebControls.ListControl.PerformSelect() +31

  System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70

  System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82

  System.Web.UI.WebControls.ListControl.OnPreRender(EventArgs e) +26

  System.Web.UI.Control.PreRenderRecursiveInternal() +86

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Control.PreRenderRecursiveInternal() +170

  System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041

--------------------------------------------------------------------------------

Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

Thanks in advance guys. :)

# July 3, 2008 7:40 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)