Remove schema from linq datacontexts (dbml)

When I add stored procedures to linq datacontext, by default visual studio prefix the stored procedure with the sql schema it resides in. Is there a way to stop this? In our environment, stored procedures can be migrated to other schemas over time and we will default to a schema based on the sql user used to connect. Do I have to do this manually or can I somehow disable the schema prefixes?

+2


a source to share


1 answer


There doesn't seem to be any means of removing schema from LINQ-SQL bound stored procedures using a constructor. All procs are displayed including their schema name, which is (to be fair) probably fine for most applications. As with most LINQ-to-SQL cases, modify your database at your own risk. Too many database changes required updating and re-creating LINQ-to-SQL dbml files.

Digging deeper, the schema name is saved in the dbml

XML support file and then included in the generated file designer.cs

that contains the functions / methods to be called.

// dbml
<Function Name="dbo.MyProc" Method="MyProc">

// designer.cs
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.MyProc")]
public int MyProc()

      

If you manually edit the XML file dbml

to remove the schema and save in Visual Studio, the code is restored as follows:



// changed dbml - removed the dbo schema
<Function Name="MyProc" Method="MyProc">

// the resultant generated code in designer.cs
[global::System.Data.Linq.Mapping.FunctionAttribute()]
public int MyProc()

      

What worked for my account is logged in with dbo by default. I'll leave the testing up to you.

This might be a workable solution - the visual designer still works like this, other elements can be added, etc. without breaking the function without a schema, and the function itself doesn't raise a designer complaint. Good luck!

+1


a source







All Articles