使用最新的PetaPoco.5.1.223,是用NuGet引用的,先将Mysql的连接字符串在Appconfig配置后,再引用PetaPoco,之后编辑Database.tt文件,保存就可以生成代码的。但是保存的时候直接就报错了,修改了很多地方都不行,还请有经验者指导一下,谢谢!
appconfig代码
1 <?xml version="1.0" encoding="utf-8"?> 2 <configuration> 3 <connectionStrings> 4 <add name="WeChat" connectionString="Server=;Database=; User=;Password=;Use Procedure Bodies=true;Charset=utf8;Allow Zero Datetime=True; Pooling=true; Max Pool Size=500;Treat Tiny As Boolean=false" providerName="MySql.Data.MySqlClient"/> 5 </connectionStrings> 6 <system.data> 7 <DbProviderFactories> 8 <remove invariant="MySql.Data.MySqlClient" /> 9 <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> 10 </DbProviderFactories> 11 </system.data></configuration>
Database.tt代码
<#@ include file="PetaPoco.Core.ttinclude" #> <# // Settings ConnectionStringName = "WeChat"; // Uses last connection string in config if not specified Namespace = "PetapocoMySql"; RepoName = "WeChat"; GenerateOperations = true; GeneratePocos = true; GenerateCommon = true; ClassPrefix = "ClassPrefixClassPrefix"; ClassSuffix = "ClassSuffixClassSuffix"; TrackModifiedColumns = false; ExplicitColumns = true; ExcludePrefix = new string[] {}; // Exclude tables by prefix. // Read schema var tables = LoadTables(); /* // Tweak Schema tables["tablename"].Ignore = true; // To ignore a table tables["tablename"].ClassName = "newname"; // To change the class name of a table tables["tablename"]["columnname"].Ignore = true; // To ignore a column tables["tablename"]["columnname"].PropertyName="newname"; // To change the property name of a column tables["tablename"]["columnname"].PropertyType="bool"; // To change the property type of a column */ // Generate output if (tables.Count>0) { #> <#@ include file="PetaPoco.Generator.ttinclude" #> <# } #>
删除PetaPoco.Core.ttinclude文件的最后一个空行就好了。