gasroot
gasroot

Reputation: 523

working with dynamic table colums and Linq to sql

i am trying to implement a dynamic data base so i have a table called metric and a table called statistic if the user of the application insert a new metric i had to add a column in the table statistic but the problem how to refresh the dbml file on run time help me please.

  db.addnewmetricInstat11(metric.MetricName, metric.Type);
  db.SubmitChanges();

ALTER PROCEDURE dbo.addnewmetricInstat10

    (
    @MetricName varchar(254),
    @TypeMetric varchar(254)
    )

AS
DECLARE @name varchar(254)
DECLARE @type varchar(254)
Set @name=@MetricName
Set @type=@TypeMetric
Declare @SQL VarChar(1000)
IF (@TypeMetric='int')
    Begin


    SELECT @SQL = 'ALTER TABLE dbo.Statistic ADD ' + @name + 'int null'
    end
ELSE  if (@TypeMetric='string')
    begin



    SELECT @SQL = 'ALTER TABLE dbo.Statistic ADD ' + @name + 'varchar(254) null'
    end
    exec (@sql)

Upvotes: 1

Views: 118

Answers (1)

user2181871
user2181871

Reputation:

you can use the sql i suggest that you insert the statistic as usual with linq and update the inserted value using sqlcommand

Upvotes: 1

Related Questions