views:

12

answers:

1

I vaguely remember reading an article a while back about being able to add queries to the designer.cs of the DataAccess layer (created by LINQ).

So in other words if you want to add some SQL directly ,rather than adding and SP to the DB and adding it to the dbml (or rerunning SQLMEtal). You could just create another partial of the DB class and and new commands to it?

For the life of me I can find the article, is this possible?

+1  A: 

All of the generated classes in the Designer.cs file are partial classes (including the DataContext). If you click on "view code" in the LinqToSql designer, it will create a .cs file to hold any more partial classes.

If you want to create your own methods that are translated into stored procs, you should examine the attributes in the System.Data.Linq.Mapping namespace.

A good introduction to these attributes is to:

  • add the stored proc in the designer
  • locate the generated code in designer.cs
  • move the generated code to the manual code file
  • drop the stored procedure from the designer

Once you see what's required, it's easier to write these by hand.

David B