0

我一直在使用 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 生成我的类时没有使用它),我不能在我的 aspx 代码后面导入 kimdata 来访问类。

但是,如果我留下这个,(即不要将其注释掉)然后我在 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
 }
}

非常感谢任何帮助或建议。

4

2 回答 2

0

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:

<compilation debug="true" defaultLanguage="C#">
      <!--########################## SubSonic Build Provider ###############################-->
      <!--This will NOT WORK in Medium Trust-->
      <buildProviders>
        <add extension=".abp" type="SubSonic.BuildProvider, SubSonic"/>
      </buildProviders>

You should create one for yourself with

    <compilation debug="true" defaultLanguage="VB">
于 2010-10-11T18:31:52.033 回答
0

大家好,感谢您的回答,但是我之前尝试了所有这些并且无法使其正常工作,幸运的是我现在已经解决了这个问题。

我通过创建我自己的类 vb 类库、添加参考 system.web、system.configuration、subsonic.dll 和关联的 dll 来做到这一点,然后我添加了一个带有我的连接字符串和服务提供程序的应用程序配置,然后生成了我的类,我然后将该类构建为dll。

我将 DLL 包含在我的网站 bin 文件夹中,现在一切都可以编译并且工作正常。

但是,这现在确实意味着我必须将我的 dal 引用为 kimDal.kimdata 但是嘿它可以工作,所以我请

谢谢大家

于 2010-10-11T19:09:41.413 回答