0

Previously I was using object context for my application. So I was using AddToTable() methods like

context.AddToTable(entity);

but now I am using DbContext and I have to use the Add method like

context.Table.Add(entity);

Now I'm having the older method called more than 300 times. So I was wondering is there any solution to change the methods solution wide.

user3275493
  • 88
  • 1
  • 11
  • You could use extension methods. – germi Feb 21 '14 at 10:48
  • @germi Could you please explain how to use it.. cause AddToTable methods are different for different table. In AddToTable "Table" is the name of the table. – user3275493 Feb 21 '14 at 10:57
  • Do you have any actual code examples of the expected input/output? – rvalvik Feb 21 '14 at 11:03
  • @rvalvik input -> dataEntity.AddTosupp_status(suppStatus); output -> dataEntity.supp_status.Add(suppStatus); but supp_status is the table name so it'll be different for different tables. – user3275493 Feb 21 '14 at 11:05

1 Answers1

0

If you want to use you Regex search and replace for this, something along these lines might do the job.

Given that you don't have any other methods named AddToX( you could use the following regex: \.AddTo([^(]+)\(

This would match .AddToX( then you replace with .\1.Add( where \1 is a back-reference, so it might be $1 depending on your flavor of regex.

That would transform .AddToX( into .X.Add(.

How you would process your code with the regex I can't answer so that would only be half the puzzle, many IDE's have project wide search and replace I guess.

Regardless, make backups before you do anything of this nature.

rvalvik
  • 1,559
  • 11
  • 15