SqlMetal 无法从 Sqlite 数据库创建 DBML

发布于 2024-08-14 11:53:52 字数 3033 浏览 5 评论 0原文

我正在尝试使用新的 Mono 2.6 SqlMetal 工具为简单的 Sqlite 数据库创建 DBML 文件。该架构非常简单,如下所示:

CREATE TABLE Tags (
    Id              INTEGER PRIMARY KEY,
    TagName         TEXT,
    Description     TEXT);
CREATE TABLE Trends (
    TagId           INTEGER NOT NULL,
    Timestamp       DATETIME NOT NULL,
    Value           TEXT,
    PRIMARY KEY (tagid, timestamp));

我尝试使用以下命令创建 DBML 文件:

sqlmetal.exe /conn:"Data Source=MyDatabase.db" /namespace:MyNamespace /provider:Sqlite /dbml:MyDatabase.dbml

我得到以下输出:

>>> Reading schema from SQLite database
<<< Writing file 'MyDatabase.dbml'
sqlmetal failed:System.InvalidOperationException: There was an error reflecting type 'DbLinq.Schema.Dbml.Database'. --->
 System.InvalidOperationException: DbLinq.Schema.Dbml.Database is inaccessible due to its protection level. Only public types can be processed
  at System.Xml.Serialization.ReflectionHelper.CheckSerializableType (System.Type type, Boolean allowPrivateConstructors ) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraTypes, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in <filename unknown>:0
  at DbLinq.Schema.Dbml.DbmlSerializer.Write (System.IO.Stream xmlStream, DbLinq.Schema.Dbml.Database dbml) [0x00000] in <filename unknown>:0
  at DbMetal.Generator.Implementation.Processor.WriteSchema (DbLinq.Schema.Dbml.Database dbSchema, ISchemaLoader schemaLoader, DbMetal.Parameters parameters) [0x00000] in <filename unknown>:0
  at DbMetal.Generator.Implementation.Processor.ProcessSchema (DbMetal.Parameters parameters) [0x00000] in <filename unknown>:0

我可以使用 /code 选项创建 C# 代码文件,但生成 DBML 时总是失败。

我是否缺少一个微妙的命令行选项,或者这个新版本的 SqlMetal 不适用于 Sqlite?

I'm trying to use the new Mono 2.6 SqlMetal tool to create the DBML file for a simple Sqlite Database. The schema is really simple as follows:

CREATE TABLE Tags (
    Id              INTEGER PRIMARY KEY,
    TagName         TEXT,
    Description     TEXT);
CREATE TABLE Trends (
    TagId           INTEGER NOT NULL,
    Timestamp       DATETIME NOT NULL,
    Value           TEXT,
    PRIMARY KEY (tagid, timestamp));

I am trying to create the DBML file using the following:

sqlmetal.exe /conn:"Data Source=MyDatabase.db" /namespace:MyNamespace /provider:Sqlite /dbml:MyDatabase.dbml

I get the following output:

>>> Reading schema from SQLite database
<<< Writing file 'MyDatabase.dbml'
sqlmetal failed:System.InvalidOperationException: There was an error reflecting type 'DbLinq.Schema.Dbml.Database'. --->
 System.InvalidOperationException: DbLinq.Schema.Dbml.Database is inaccessible due to its protection level. Only public types can be processed
  at System.Xml.Serialization.ReflectionHelper.CheckSerializableType (System.Type type, Boolean allowPrivateConstructors ) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportClassMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Xml.Serialization.TypeData typeData, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping (System.Type type, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0
  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.Xml.Serialization.XmlAttributeOverrides overrides, System.Type[] extraTypes, System.Xml.Serialization.XmlRootAttribute root, System.String defaultNamespace) [0x00000] in <filename unknown>:0  at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in <filename unknown>:0
  at DbLinq.Schema.Dbml.DbmlSerializer.Write (System.IO.Stream xmlStream, DbLinq.Schema.Dbml.Database dbml) [0x00000] in <filename unknown>:0
  at DbMetal.Generator.Implementation.Processor.WriteSchema (DbLinq.Schema.Dbml.Database dbSchema, ISchemaLoader schemaLoader, DbMetal.Parameters parameters) [0x00000] in <filename unknown>:0
  at DbMetal.Generator.Implementation.Processor.ProcessSchema (DbMetal.Parameters parameters) [0x00000] in <filename unknown>:0

I can use the /code option to create a C# code file, but it always fails when generating a DBML.

Am I missing a subtle commandline option or is this new build of SqlMetal not working for Sqlite?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兔姬 2024-08-21 11:53:52

你相信我以前没有尝试过生成 DBML 文件吗?

简短版本:这是您遇到的错误,没有解决方法。我已将其归档为 http://code.google.com/ p/dblinq2007/issues/detail?id=171

更长的版本:似乎没有一个简单的解决方案(除了“jettison System.Xml.Serialization”),因为引用的 DbLinq.Schema.Dbml.Database 类型不能由于显而易见的原因,来自 System.Data.Linq.dll 的 public。由于不同的错误,在 Linux 下构建 DbLinq 并使用 DbMetal.exe 的“解决方法”不起作用。

带来不便敬请谅解。

<sheepish-grin>Would you believe I haven't tried to generate a DBML file before?</sheepish-grin>

Short version: this is a bug that you're hitting, with no workaround. I've filed it as http://code.google.com/p/dblinq2007/issues/detail?id=171.

Longer version: There doesn't appear to be a simple solution to this (aside from "jettison System.Xml.Serialization"), as the referenced DbLinq.Schema.Dbml.Database type can't be public from System.Data.Linq.dll, for ~obvious reasons. A "workaround" of building DbLinq under Linux and using DbMetal.exe doesn't work, due to a different bug.

Sorry for the inconvenience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文