简体   繁体   中英

changing table name and column name in linq-to-sql

I'm using linq-to-sql to get data from my database. I want to change the name of a table and change the name of 2 columns. I know how to do that but the problem is that I've written several queries already against that table and if I change the database, the queries need to change as well.

Is there a way to make changes to the database without having to redo the queries and the datacontext?

Thanks.

At least you need to update the mapping between your Entity and Database (Table name, Column name). All your Queries will still be the same.

The update will be from Visual studio ORM Designer( if you are using )

[OR]

With attribute in Datacontext.

[Table(Name="UpdatedName")] and [Column(Name="UpdatedName")]

You can also call the Stored-Proc from LinQ . Write the query in your Stored-Proc to change the Schema and finally call this Proc from LINQ .

If it is read-only queries you can also add a view to the database with the old names.

However, if it is just a couple of queries Visual Studio will very quickly show you where to make the appropriate changes (Linqs2sql is strongly typed after all). I recommend you just change all the queries and the datacontext as well becausee on the long term it will be more clear what is happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM