第一步

用SQLiteStudio生成一个新的数据库,sqlitetest,新建一张表test,建立一个主键字段ID,一个字符字段Name,建立完成,留待后用。

第二步

用VS2010建立一个sqlitetest的控制台程序,添加System.Data.SQLite和System.Data.SQLite.Linq引用(.Net版本的SQLite在http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki下载,目前版本1.0.87.0对应SQLite 3.7.17)

第三步

用CodeSmith正常生成项目,添加sqlitetest.Data、sqlitetest.Data.GenericClient和sqlitetest.Entities三个项目到程序中,并添加引用

问题1

这时编译会提示“命名空间“sqlitetest”中不存在类型或命名空间名称“Data”。是否缺少程序集引用?”,需要修改程序的目标框架从.NET Framework 4 Client Profile改成.NET Framework 4。

问题2

这时运行会抛出异常“Unable to load NetTiersServiceSection”,需要添加app.config文件,添加下面的内容到config文件的最前面

<configSections>
<section name="sqlitetest.Data"
type="sqlitetest.Data.Bases.NetTiersServiceSection, sqlitetest.Data"
allowDefinition="MachineToApplication"
restartOnExternalChanges="true" />
</configSections>

还有两段内容也需要复制到config文件中,具体见生成的report.html

问题3

这时运行会抛出异常“未能加载文件或程序集“sqlitetest.Data.SqlClient”或它的某一个依赖项。系统找不到指定的文件。”,因为之前生成的代码还是使用SqlClient,而不是产生的GenericClient

type="sqlitetest.Data.SqlClient.SqlNetTiersProvider, sqlitetest.Data.SqlClient"

上面这行改成

type="sqlitetest.Data.GenericClient.GenericNetTiersProvider, sqlitetest.Data.GenericClient"

——————————

providerInvariantName="System.Data.SqlClient"

上面这行改成

providerInvariantName="System.Data.SQLite"

问题4

这时运行会抛出异常“SQL logic error or missing database near ".": syntax error”,原因是生成的dbCommand类似这样:

INSERT INTO .[test]
(
[Name]
)
VALUES
(
@Name
);
注意表名前面有个".",费了点功夫去跟踪了下这个东东的来历,长话短说,这个东东来自于System.Data.SQLite.Procedures.cst,第70行:

string owner = GetOwnerName(SourceTable, true);
改成这样:
string owner = GetOwnerName(SourceTable);

重新生成即可

问题5

GenericTestProviderBase.generated.cs,第646行注释掉

entity.Id = (System.Int64) reader["test.ID"];

换用644行

entity.Id = (long)reader["Id"];

修改GenericEntityProviderBase.generated.cst,第1024行,去掉注释

entity.Id = (long)reader["Id"];
注释掉1038行

//entity.<%=GetPropertyName(cols[i])%> = (<%=castTo%>) reader["<%=cols[i]%>"];

问题6

System.Data.SQLite.Procedures.cst,第288行

tempParams += string.Format("AND [{1}] = @{0} {2}", prefix + GetPropertyName(SourceTable.PrimaryKey.MemberColumns[i]), SourceTable.PrimaryKey.MemberColumns[i], Environment.NewLine) ;

改为

tempParams += string.Format("AND [{1}] = @{0} {2}", prefix + GetPropertyName(SourceTable.PrimaryKey.MemberColumns[i]), SourceTable.PrimaryKey.MemberColumns[i].Name, Environment.NewLine) ;

解决UPDATE时的异常

最新文章

  1. 【原创】开源Math.NET基础数学类库使用(15)C#计算矩阵行列式
  2. winrt简单克隆对象
  3. Jquery挂事件与移除事件
  4. iframe的内容增高或缩减时设置其iframe的高度的处理方案
  5. css3 @font-face
  6. 不同hadoop集群之间迁移hive数据
  7. QQ粘性布局
  8. iOS的I/O操作
  9. 如何去掉word的背影图片?
  10. java学习一目了然&mdash;&mdash;File类文件处理
  11. 了解单位em和px的区别
  12. 解决错误 fatal error C1010: unexpected end of file while looking for precompiled head
  13. silverlight WPF 水纹文本框
  14. 【BZOJ2134】单位错选(数学期望,动态规划)
  15. 问题(一) DebugAugmenter
  16. 小米平板4 Plus获取Root超级权限的步骤
  17. (译)MySQL的10个基本性能技巧
  18. guava-retrying 源码解析(停止策略详解)
  19. Codeforces Round #131 Div1 B
  20. HDU 2891

热门文章

  1. Redis未授权访问反弹shell
  2. java——修改txt文件中某一行的内容
  3. Notepad++实用插件
  4. tomcat直接访问webinfo里的jsp
  5. 性能测试工具LoadRunner14-LR之Controller 简介
  6. javascript典型实例
  7. mongodb开机启动
  8. CheckBox全选、取消全选
  9. JVM:java类的加载机制
  10. Hibernate课程 初探一对多映射3-1 单向多对一简介