How do I get the schema of a stored procedure using Linq to SQL?

Basically I'm trying to get a list of parameters of a stored procedure using Linq to SQL? Is there a way to do this?

+1


source to share


2 answers


During development? Just drag the stored procedure onto the LINQ designer surface.


At run time?

You need sql like this:



SELECT *
FROM syscolumns
WHERE id =
(
  SELECT id
  FROM sysobjects
  WHERE Name = @ProcName
)

      

Which can be called by LinqToSql like this:

var params = 
  db.sysobjects
  .Where(o => o.Name == ProcName)
  .SelectMany(o =>
    db.syscolumns
    .Where(c => c.id == o.id)
  )

      

+2


source


Maybe System.Data.SqlClient.SqlCommandBuilder.DeriveParameters () will help.



+2


source







All Articles