SUBSONIC 通过 VS2008 使用 subcommander 导致以下错误 - 请帮忙
我一直在使用子命令来生成我的 dal。我使用 vb.net 和 sqlexpress 和 .net 3.5
我的 webconfig 看起来像这样
<!-- add subsonic in for dal-->
<section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" allowDefinition="MachineToApplication" requirePermission="false"/>
</configSections>
<connectionStrings>
<!-- Development connection string -->
<add name="kimconnection" connectionString="Data Source=7NQ384J\SQLExpress;Initial Catalog=kim2;Integrated Security=True;"/>
</connectionStrings>
<!--Add my provider for subsonic to my database-->
<SubSonicService defaultProvider="kimAppProvider">
<providers>
<clear/>
<add name="kimAppProvider" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="kimconnection" generatedNamespace="kimdata"/>
</providers>
</SubSonicService>
<appSettings>
<!--Add my provider for generating my dal / classes-->
<buildProviders>
<add extension=".abp" type="SubSonic.BuildProvider, SubSonic"/>
</buildProviders>
好的,我的问题是,如果我注释掉我的构建提供程序(因为我认为在使用 subcommander 生成我的类时没有使用它),我无法导入 kimdata在我的 aspx 代码后面访问类。
但是,如果我留下这个(即不要将其注释掉),然后我在 Visual Studio 中调试我的代码,我会收到超过 200 个错误,错误消息是“语句不能出现在方法体之外”,
该错误似乎在我编译的情况下显示此错误app_code 在调试时,问题是这是 c#,我使用 vb,我生成的类是 vb,默认语言是 vb,那么为什么这是在 c# 中,这是我收到错误的原因吗?或者是否还有其他原因,我该如何解决这个问题,因为我的应用程序因存在许多错误而无法运行,
#ExternalChecksum("d:\dscott\windows\Visual Studio 2008\WebSites\KimV2\App_Code\builder.abp","{406ea660-64cf-4c82-b6f0-42d48172a799}","ECAA88F7FA0BF610A5A26CF545DCD3AA")
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;
namespace kimdata
{
/// <summary>
/// Strongly-typed collection for the AlertMessage class.
/// </summary>
[Serializable]
public partial class AlertMessageCollection : ActiveList<AlertMessage, AlertMessageCollection>
{
public AlertMessageCollection() {}
/// <summary>
/// Filters an existing collection based on the set criteria. This is an in-memory filter
/// Thanks to developingchris for this!
/// </summary>
/// <returns>AlertMessageCollection</returns>
public AlertMessageCollection Filter()
{
for (int i = this.Count - 1; i > -1; i--)
{
AlertMessage o = this[i];
foreach (SubSonic.Where w in this.wheres)
{
bool remove = false;
System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
if (pi.CanRead)
{
object val = pi.GetValue(o, null);
switch (w.Comparison)
{
case SubSonic.Comparison.Equals:
if (!val.Equals(w.ParameterValue))
{
remove = true;
}
break;
}
}
if (remove)
{
this.Remove(o);
break;
}
}
}
return this;
}
}
/// <summary>
/// This is an ActiveRecord class which wraps the alertMessages table.
/// </summary>
[Serializable]
public partial class AlertMessage : ActiveRecord<AlertMessage>, IActiveRecord
{
#region .ctors and Default Settings
public AlertMessage()
{
SetSQLProps();
InitSetDefaults();
MarkNew();
}
private void InitSetDefaults() { SetDefaults(); }
public AlertMessage(bool useDatabaseDefaults)
{
SetSQLProps();
if(useDatabaseDefaults)
ForceDefaults();
MarkNew();
}
public AlertMessage(object keyID)
{
SetSQLProps();
InitSetDefaults();
LoadByKey(keyID);
}
public AlertMessage(string columnName, object columnValue)
{
SetSQLProps();
InitSetDefaults();
LoadByParam(columnName,columnValue);
}
protected static void SetSQLProps() { GetTableSchema(); }
#endregion
#region Schema and Query Accessor
public static Query CreateQuery() { return new Query(Schema); }
public static TableSchema.Table Schema
{
get
{
if (BaseSchema == null)
SetSQLProps();
return BaseSchema;
}
}
private static void GetTableSchema()
{
if(!IsSchemaInitialized)
{
//Schema declaration
TableSchema.Table schema = new TableSchema.Table("alertMessages", TableType.Table, DataService.GetInstance("kimAppProvider"));
schema.Columns = new TableSchema.TableColumnCollection();
schema.SchemaName = @"dbo";
//columns
TableSchema.TableColumn colvarMessageID = new TableSchema.TableColumn(schema);
colvarMessageID.ColumnName = "messageID";
colvarMessageID.DataType = DbType.Int32;
colvarMessageID.MaxLength = 0;
colvarMessageID.AutoIncrement = true;
colvarMessageID.IsNullable = false;
colvarMessageID.IsPrimaryKey = true;
colvarMessageID.IsForeignKey = false;
colvarMessageID.IsReadOnly = false;
colvarMessageID.DefaultSetting = @"";
colvarMessageID.ForeignKeyTableName = "";
schema.Columns.Add(colvarMessageID);
TableSchema.TableColumn colvarDocumentType = new TableSchema.TableColumn(schema);
colvarDocumentType.ColumnName = "documentType";
colvarDocumentType.DataType = DbType.AnsiString;
colvarDocumentType.MaxLength = 50;
colvarDocumentType.AutoIncrement = false;
colvarDocumentType.IsNullable = false;
colvarDocumentType.IsPrimaryKey = false;
colvarDocumentType.IsForeignKey = false;
colvarDocumentType.IsReadOnly = false;
colvarDocumentType.DefaultSetting = @"";
colvarDocumentType.ForeignKeyTableName = "";
schema.Columns.Add(colvarDocumentType);
TableSchema.TableColumn colvarMessageTitle = new TableSchema.TableColumn(schema);
colvarMessageTitle.ColumnName = "messageTitle";
colvarMessageTitle.DataType = DbType.AnsiString;
colvarMessageTitle.MaxLength = 200;
colvarMessageTitle.AutoIncrement = false;
colvarMessageTitle.IsNullable = false;
colvarMessageTitle.IsPrimaryKey = false;
colvarMessageTitle.IsForeignKey = false;
colvarMessageTitle.IsReadOnly = false;
colvarMessageTitle.DefaultSetting = @"";
colvarMessageTitle.ForeignKeyTableName = "";
schema.Columns.Add(colvarMessageTitle);
TableSchema.TableColumn colvarMsgPublishDate = new TableSchema.TableColumn(schema);
colvarMsgPublishDate.ColumnName = "msgPublishDate";
colvarMsgPublishDate.DataType = DbType.DateTime;
colvarMsgPublishDate.MaxLength = 0;
colvarMsgPublishDate.AutoIncrement = false;
colvarMsgPublishDate.IsNullable = false;
colvarMsgPublishDate.IsPrimaryKey = false;
colvarMsgPublishDate.IsForeignKey = false;
colvarMsgPublishDate.IsReadOnly = false;
colvarMsgPublishDate.DefaultSetting = @"";
colvarMsgPublishDate.ForeignKeyTableName = "";
schema.Columns.Add(colvarMsgPublishDate);
TableSchema.TableColumn colvarXml = new TableSchema.TableColumn(schema);
colvarXml.ColumnName = "xml";
colvarXml.DataType = DbType.String;
colvarXml.MaxLength = 1073741823;
colvarXml.AutoIncrement = false;
colvarXml.IsNullable = false;
colvarXml.IsPrimaryKey = false;
colvarXml.IsForeignKey = false;
colvarXml.IsReadOnly = false;
colvarXml.DefaultSetting = @"";
colvarXml.ForeignKeyTableName = "";
schema.Columns.Add(colvarXml);
TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
colvarCreatedOn.ColumnName = "createdOn";
colvarCreatedOn.DataType = DbType.DateTime;
colvarCreatedOn.MaxLength = 0;
colvarCreatedOn.AutoIncrement = false;
colvarCreatedOn.IsNullable = false;
colvarCreatedOn.IsPrimaryKey = false;
colvarCreatedOn.IsForeignKey = false;
colvarCreatedOn.IsReadOnly = false;
colvarCreatedOn.DefaultSetting = @"";
colvarCreatedOn.ForeignKeyTableName = "";
schema.Columns.Add(colvarCreatedOn);
TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
colvarCreatedBy.ColumnName = "createdBy";
colvarCreatedBy.DataType = DbType.String;
colvarCreatedBy.MaxLength = 50;
colvarCreatedBy.AutoIncrement = false;
colvarCreatedBy.IsNullable = false;
colvarCreatedBy.IsPrimaryKey = false;
colvarCreatedBy.IsForeignKey = false;
colvarCreatedBy.IsReadOnly = false;
colvarCreatedBy.DefaultSetting = @"";
colvarCreatedBy.ForeignKeyTableName = "";
schema.Columns.Add(colvarCreatedBy);
TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
colvarModifiedOn.ColumnName = "modifiedOn";
colvarModifiedOn.DataType = DbType.DateTime;
colvarModifiedOn.MaxLength = 0;
colvarModifiedOn.AutoIncrement = false;
colvarModifiedOn.IsNullable = true;
colvarModifiedOn.IsPrimaryKey = false;
colvarModifiedOn.IsForeignKey = false;
colvarModifiedOn.IsReadOnly = false;
colvarModifiedOn.DefaultSetting = @"";
colvarModifiedOn.ForeignKeyTableName = "";
schema.Columns.Add(colvarModifiedOn);
TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
colvarModifiedBy.ColumnName = "modifiedBy";
colvarModifiedBy.DataType = DbType.String;
colvarModifiedBy.MaxLength = 50;
colvarModifiedBy.AutoIncrement = false;
colvarModifiedBy.IsNullable = true;
colvarModifiedBy.IsPrimaryKey = false;
colvarModifiedBy.IsForeignKey = false;
colvarModifiedBy.IsReadOnly = false;
colvarModifiedBy.DefaultSetting = @"";
colvarModifiedBy.ForeignKeyTableName = "";
schema.Columns.Add(colvarModifiedBy);
BaseSchema = schema;
//add this schema to the provider
//so we can query it later
DataService.Providers["kimAppProvider"].AddSchema("alertMessages",schema);
}
}
#endregion
#region Props
PK Collections
#endregion
#region Deep Save
#endregion
}
}
非常感谢任何帮助或建议。
担
Ive been using subcommander to generate my dal. Im using vb.net and sqlexpress and .net 3.5
My webconfig looks like this
<!-- add subsonic in for dal-->
<section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" allowDefinition="MachineToApplication" requirePermission="false"/>
</configSections>
<connectionStrings>
<!-- Development connection string -->
<add name="kimconnection" connectionString="Data Source=7NQ384J\SQLExpress;Initial Catalog=kim2;Integrated Security=True;"/>
</connectionStrings>
<!--Add my provider for subsonic to my database-->
<SubSonicService defaultProvider="kimAppProvider">
<providers>
<clear/>
<add name="kimAppProvider" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="kimconnection" generatedNamespace="kimdata"/>
</providers>
</SubSonicService>
<appSettings>
<!--Add my provider for generating my dal / classes-->
<buildProviders>
<add extension=".abp" type="SubSonic.BuildProvider, SubSonic"/>
</buildProviders>
Ok my problem is that if I comment out my build provider (as I thought I didnt use it when using subcommander to generate my classes), I cant do imports kimdata inside my aspx code behinds to access to classes.
However if I leave this is, (ie dont comment it out) and I then debug my code in visual studio I get over 200 errors, the error message is "statement cannot appear outside method body"
the error seems to show this im my compiled app_code when its debugging, the thing is this is c#, im using vb, the classes I generate are vb, and the default language is vb, so why is this in c# and is this the reason im getting the errors? or is there some other reason, and how can I resolve this as my app wont run as there are to many erorrs,
#ExternalChecksum("d:\dscott\windows\Visual Studio 2008\WebSites\KimV2\App_Code\builder.abp","{406ea660-64cf-4c82-b6f0-42d48172a799}","ECAA88F7FA0BF610A5A26CF545DCD3AA")
using System;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Xml;
using System.Xml.Serialization;
using SubSonic;
using SubSonic.Utilities;
namespace kimdata
{
/// <summary>
/// Strongly-typed collection for the AlertMessage class.
/// </summary>
[Serializable]
public partial class AlertMessageCollection : ActiveList<AlertMessage, AlertMessageCollection>
{
public AlertMessageCollection() {}
/// <summary>
/// Filters an existing collection based on the set criteria. This is an in-memory filter
/// Thanks to developingchris for this!
/// </summary>
/// <returns>AlertMessageCollection</returns>
public AlertMessageCollection Filter()
{
for (int i = this.Count - 1; i > -1; i--)
{
AlertMessage o = this[i];
foreach (SubSonic.Where w in this.wheres)
{
bool remove = false;
System.Reflection.PropertyInfo pi = o.GetType().GetProperty(w.ColumnName);
if (pi.CanRead)
{
object val = pi.GetValue(o, null);
switch (w.Comparison)
{
case SubSonic.Comparison.Equals:
if (!val.Equals(w.ParameterValue))
{
remove = true;
}
break;
}
}
if (remove)
{
this.Remove(o);
break;
}
}
}
return this;
}
}
/// <summary>
/// This is an ActiveRecord class which wraps the alertMessages table.
/// </summary>
[Serializable]
public partial class AlertMessage : ActiveRecord<AlertMessage>, IActiveRecord
{
#region .ctors and Default Settings
public AlertMessage()
{
SetSQLProps();
InitSetDefaults();
MarkNew();
}
private void InitSetDefaults() { SetDefaults(); }
public AlertMessage(bool useDatabaseDefaults)
{
SetSQLProps();
if(useDatabaseDefaults)
ForceDefaults();
MarkNew();
}
public AlertMessage(object keyID)
{
SetSQLProps();
InitSetDefaults();
LoadByKey(keyID);
}
public AlertMessage(string columnName, object columnValue)
{
SetSQLProps();
InitSetDefaults();
LoadByParam(columnName,columnValue);
}
protected static void SetSQLProps() { GetTableSchema(); }
#endregion
#region Schema and Query Accessor
public static Query CreateQuery() { return new Query(Schema); }
public static TableSchema.Table Schema
{
get
{
if (BaseSchema == null)
SetSQLProps();
return BaseSchema;
}
}
private static void GetTableSchema()
{
if(!IsSchemaInitialized)
{
//Schema declaration
TableSchema.Table schema = new TableSchema.Table("alertMessages", TableType.Table, DataService.GetInstance("kimAppProvider"));
schema.Columns = new TableSchema.TableColumnCollection();
schema.SchemaName = @"dbo";
//columns
TableSchema.TableColumn colvarMessageID = new TableSchema.TableColumn(schema);
colvarMessageID.ColumnName = "messageID";
colvarMessageID.DataType = DbType.Int32;
colvarMessageID.MaxLength = 0;
colvarMessageID.AutoIncrement = true;
colvarMessageID.IsNullable = false;
colvarMessageID.IsPrimaryKey = true;
colvarMessageID.IsForeignKey = false;
colvarMessageID.IsReadOnly = false;
colvarMessageID.DefaultSetting = @"";
colvarMessageID.ForeignKeyTableName = "";
schema.Columns.Add(colvarMessageID);
TableSchema.TableColumn colvarDocumentType = new TableSchema.TableColumn(schema);
colvarDocumentType.ColumnName = "documentType";
colvarDocumentType.DataType = DbType.AnsiString;
colvarDocumentType.MaxLength = 50;
colvarDocumentType.AutoIncrement = false;
colvarDocumentType.IsNullable = false;
colvarDocumentType.IsPrimaryKey = false;
colvarDocumentType.IsForeignKey = false;
colvarDocumentType.IsReadOnly = false;
colvarDocumentType.DefaultSetting = @"";
colvarDocumentType.ForeignKeyTableName = "";
schema.Columns.Add(colvarDocumentType);
TableSchema.TableColumn colvarMessageTitle = new TableSchema.TableColumn(schema);
colvarMessageTitle.ColumnName = "messageTitle";
colvarMessageTitle.DataType = DbType.AnsiString;
colvarMessageTitle.MaxLength = 200;
colvarMessageTitle.AutoIncrement = false;
colvarMessageTitle.IsNullable = false;
colvarMessageTitle.IsPrimaryKey = false;
colvarMessageTitle.IsForeignKey = false;
colvarMessageTitle.IsReadOnly = false;
colvarMessageTitle.DefaultSetting = @"";
colvarMessageTitle.ForeignKeyTableName = "";
schema.Columns.Add(colvarMessageTitle);
TableSchema.TableColumn colvarMsgPublishDate = new TableSchema.TableColumn(schema);
colvarMsgPublishDate.ColumnName = "msgPublishDate";
colvarMsgPublishDate.DataType = DbType.DateTime;
colvarMsgPublishDate.MaxLength = 0;
colvarMsgPublishDate.AutoIncrement = false;
colvarMsgPublishDate.IsNullable = false;
colvarMsgPublishDate.IsPrimaryKey = false;
colvarMsgPublishDate.IsForeignKey = false;
colvarMsgPublishDate.IsReadOnly = false;
colvarMsgPublishDate.DefaultSetting = @"";
colvarMsgPublishDate.ForeignKeyTableName = "";
schema.Columns.Add(colvarMsgPublishDate);
TableSchema.TableColumn colvarXml = new TableSchema.TableColumn(schema);
colvarXml.ColumnName = "xml";
colvarXml.DataType = DbType.String;
colvarXml.MaxLength = 1073741823;
colvarXml.AutoIncrement = false;
colvarXml.IsNullable = false;
colvarXml.IsPrimaryKey = false;
colvarXml.IsForeignKey = false;
colvarXml.IsReadOnly = false;
colvarXml.DefaultSetting = @"";
colvarXml.ForeignKeyTableName = "";
schema.Columns.Add(colvarXml);
TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
colvarCreatedOn.ColumnName = "createdOn";
colvarCreatedOn.DataType = DbType.DateTime;
colvarCreatedOn.MaxLength = 0;
colvarCreatedOn.AutoIncrement = false;
colvarCreatedOn.IsNullable = false;
colvarCreatedOn.IsPrimaryKey = false;
colvarCreatedOn.IsForeignKey = false;
colvarCreatedOn.IsReadOnly = false;
colvarCreatedOn.DefaultSetting = @"";
colvarCreatedOn.ForeignKeyTableName = "";
schema.Columns.Add(colvarCreatedOn);
TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
colvarCreatedBy.ColumnName = "createdBy";
colvarCreatedBy.DataType = DbType.String;
colvarCreatedBy.MaxLength = 50;
colvarCreatedBy.AutoIncrement = false;
colvarCreatedBy.IsNullable = false;
colvarCreatedBy.IsPrimaryKey = false;
colvarCreatedBy.IsForeignKey = false;
colvarCreatedBy.IsReadOnly = false;
colvarCreatedBy.DefaultSetting = @"";
colvarCreatedBy.ForeignKeyTableName = "";
schema.Columns.Add(colvarCreatedBy);
TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
colvarModifiedOn.ColumnName = "modifiedOn";
colvarModifiedOn.DataType = DbType.DateTime;
colvarModifiedOn.MaxLength = 0;
colvarModifiedOn.AutoIncrement = false;
colvarModifiedOn.IsNullable = true;
colvarModifiedOn.IsPrimaryKey = false;
colvarModifiedOn.IsForeignKey = false;
colvarModifiedOn.IsReadOnly = false;
colvarModifiedOn.DefaultSetting = @"";
colvarModifiedOn.ForeignKeyTableName = "";
schema.Columns.Add(colvarModifiedOn);
TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
colvarModifiedBy.ColumnName = "modifiedBy";
colvarModifiedBy.DataType = DbType.String;
colvarModifiedBy.MaxLength = 50;
colvarModifiedBy.AutoIncrement = false;
colvarModifiedBy.IsNullable = true;
colvarModifiedBy.IsPrimaryKey = false;
colvarModifiedBy.IsForeignKey = false;
colvarModifiedBy.IsReadOnly = false;
colvarModifiedBy.DefaultSetting = @"";
colvarModifiedBy.ForeignKeyTableName = "";
schema.Columns.Add(colvarModifiedBy);
BaseSchema = schema;
//add this schema to the provider
//so we can query it later
DataService.Providers["kimAppProvider"].AddSchema("alertMessages",schema);
}
}
#endregion
#region Props
PK Collections
#endregion
#region Deep Save
#endregion
}
}
Any help or advice greatly appreciated.
Dan
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
实际上,您必须告诉亚音速使用哪种代码语言来生成代码。
如果您使用子命令,则可以将
/lang vb
参数添加到命令行。如果您使用构建提供程序,我 95% 确定 subsonic 会选择正确的语言来单独使用。根据文档,您可能犯的一个错误是:http://subsonicproject.com/docs/Setting_up_SubSonic_2。 x buildprovider 部分必须位于编译标记内:您应该使用以下命令为自己创建一个
Actually you have to tell subsonic which code language to use for code generation.
If you use subcommander you can add a
/lang vb
parameter to the command line. If you use the build provider I am 95% certain subsonic will choose the right language to use by itself. One possible mistake you made is that, according to the docs: http://subsonicproject.com/docs/Setting_up_SubSonic_2.x the buildprovider section has to be inside a compilation tag:You should create one for yourself with
大家好,感谢您的回答,但是我之前尝试过所有这些,但无法使其工作,幸运的是我现在已经解决了这个问题。
我通过创建自己的类 vb 类库,添加参考 system.web、system.configuration、subsonic.dll 和关联的 dll 来完成此操作,然后使用连接字符串和服务提供程序添加应用程序配置,然后生成我的类,我然后将该类构建为 dll。
我将 DLL 包含在我的网站 bin 文件夹中,现在一切都可以编译并正常工作。
然而,这现在意味着我必须将我的 dal 引用为 kimDal.kimdata 但是嘿它可以工作所以我请
感谢所有
丹
Hi Everyone and thanks for your answers, however i tried all of these previously and couldnt get it to work, luckily i have now fixed the issue.
I did this by creating my own class vb class library, adding the reference system.web, system.configuration, subsonic.dll and associated dlls, i then added an app config with my connection string and service provider and then generated my classes, i then built the class as a dll.
I included the DLL inside my website bin folder and now everything compiles and works fine.
However this does now mean i have to reference my dal as kimDal.kimdata but hey it works so im please
Thanks to all
dan