Linq Mapping dbml - capture stored proc packages for error reporting

When using dbml autogeneration in a visual studio, a stored procedure call usually ends this way

[global::System.Data.Linq.Mapping.FunctionAttribute(Name="MYDB.ui_index_group_upd")] public int ui_index_group_upd([global::System.Data.Linq.Mapping.ParameterAttribute(DbType="Int")] System.Nullable<int> group_id, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(32)")] string group_code) { IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), group_id, group_code); return ((int)(result.ReturnValue)); } 

and it’s usually called like that ...

  using (var db = new L2SDataContext(base._connectionString)) { var result = db.ui_index_group_upd(1, "foo"); } 

Everything is good.

However, what I am trying to achieve is a global way of capturing errors and reporting all such method calls in such a way as to record the proc name and values ​​for all parameters passed in case of a problem

I would prefer not to write code code for each method and, for obvious reasons, I do not want to change the autogen code.

I am thinking of a layer between my call and the dbml method, but I, although maybe someone faced a similar problem, so I thought I put it there before spending time messing up until I get a reasonable answer, I I think the trick is an elegant way of listing parm and the name proc, etc.

I hope this makes sense, all reviews are rated

+4
source share
1 answer

I think replacing MSLinqToSqlGenerator with something else is the cleanest solution, and this can be done in several ways. You could for example

  • Use a tool like T4 Toolbox: LINQ to SQL or Reegenerator class generator and modify the provided template to suit your needs. This is probably the easiest way.

  • Create code with T4 using a custom template. You will need to create a T4 template that uses the XML data from the .DBML file. You probably need to disable DBML code generation by setting the Custom Tool property to empty. The downside is that you will need to run T4 generation every time you modify the .DBML file.

  • Create a custom tool to generate code for using XML data from a .DBML file and some template solution (T4 or XSLT, possibly). This approach may be the most flexible, the only drawback is that you have to use a custom tool on every development machine.

I'm not sure which is optimal for your situation, but I would probably think about using the T4 Toolbox. The T4 template that he uses is pretty standard and can easily be changed if necessary.

+2
source

All Articles