21

How would you make the LINQ-TO-SQL type provider, generate or/and regenerate the classes?

I've just added a new table to my database, and the type provider can't figure that out. I've tried to delete the line with the type provider, and type it once more - no luck. I've also tried to do a rebuild.. still no luck.

Edit:

I've defined the type provider like:

[<Generate>]
type dbSchema = SqlDataConnection<"conString">

and using it like:

let ctx = dbSchema.GetDataContext()

1
  • Please provide some code
    – Ankur
    Oct 19, 2011 at 12:40

1 Answer 1

23

You're right - this seems to be quite tricky. I'm using SqlDataConnection type provider in a script file and the only way to update the schema that I've found so far is to make some minor (irrelevant) change in the connection string. For example, add space after = of one of the parameters:

[<Generate>]
type Northwind = TypeProviders.SqlDataConnection
  <"data source=.\\sqlexpress;initial catalog=Northwind;integrated security=True">

[<Generate>]
type Northwind = TypeProviders.SqlDataConnection
  <"data source=.\\sqlexpress;initial catalog=Northwind;integrated security= True">

//                                                                          ^ here

The schema seems to be cached using connection string as the key, so if you change it back, you get the old schema again. I guess this is probably a bug, so adding whitespace is a possible workaround.

There is also a parameter ForceUpdate, but that doesn't seem to have any effect and the documentation doesn't say much about it.

5
  • 9
    The "irrelevant change to the string" is indeed one working way to force an update; we're aware of the API/usability issues here and we will have something better for the eventual Beta.
    – Brian
    Oct 19, 2011 at 15:56
  • 17
    any news on this? it's been >4 years and I'm making irrelevant changes to the connection string when I need an update, and wishing I didn't have to.
    – Maslow
    Jul 15, 2015 at 19:01
  • Little question: what happens when the type provider is trying to access a resource which is not available at compile-time (internet down, or remote host down, etc...)?
    – TesX
    Nov 19, 2016 at 14:03
  • 3
    Six years later, is the recommended practice still to insert benign garbage into the connection string?
    – J D
    May 22, 2017 at 0:53
  • 2
    It is now the year of our lord, two-thousand twenty, we continually inserteth spaces hither and yon to regenerate types, as prescribed by this tome.
    – Asti
    Mar 16, 2020 at 6:15

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.