本文介绍了类型提供者:如何重新生成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将如何创建LINQ-TO-SQL类型提供程序,生成或/和重新生成类?

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.

我已经定义了类型提供程序,例如:

I've defined the type provider like:

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

并像这样使用它:

let ctx = dbSchema.GetDataContext()

推荐答案

您是对的-这似乎很棘手.我在脚本文件中使用SqlDataConnection类型提供程序,并且更新到目前为止我发现的架构的唯一方法是对连接字符串进行一些较小(无关)的更改.例如,在参数之一的=之后添加空格:

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.

还有一个参数ForceUpdate,但这似乎没有任何效果,并且对此不多说.

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

这篇关于类型提供者:如何重新生成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 19:45