SubSonic 3.0.0.2/3 | SimpleRepository

时间:2009-07-22 10:51:43

标签: subsonic

我正在使用sql server 2008,遵循最新约定我使用除[dbo]之外的新架构。[tablename]现在看起来像这个[newdbo]。[tablename]。现在的问题是,SimpleRepository无法找到[newdbo]。[tablename],我认为它正在寻找[dbo]而不是[newdbo],因为我的类被定义为:

这是我的表:架构/所有者是“亲吻”

CREATE TABLE [kiss].[Users](
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [UserName] [nvarchar](20) NOT NULL,
    [UserPassword] [varbinary](128) NULL,
    [UserTypeID] [tinyint] NOT NULL,
    [ByPassAccessRestrictionsFlag] [bit] NOT NULL,
    [IsEnforcePasswordPolicy] [bit] NOT NULL,
    [PasswordExpirationDate] [datetime] NULL,
    [IsPwdChangeNextLogin] [bit] NOT NULL,
    [ShowLatestNewsFlag] [bit] NOT NULL,
    [SortRowNumber] [int] NOT NULL,
    [CreatedDate] [datetime] NOT NULL,
    [CreatedBy] [nvarchar](20) NOT NULL,
    [UpdatedDate] [datetime] NOT NULL,
    [UpdatedBy] [nvarchar](20) NOT NULL,
    [DeletedDate] [int] NULL,
    [eCrewID] [varchar](10) NULL,
    [EntityTypeID] [int] NOT NULL
)
GO

这是我的班级:

public class Users
{
    public Int32 ID { get; set; }
    public String UserName { get; set; }
    public Byte[] UserPassword { get; set; }
    public Byte UserTypeID { get; set; }
    public Boolean ByPassAccessRestrictionsFlag { get; set; }
    public Boolean IsEnforcePasswordPolicy { get; set; }
    public DateTime PasswordExpirationDate { get; set; }
    public Boolean IsPwdChangeNextLogin { get; set; }
    public Boolean ShowLatestNewsFlag { get; set; }
    public Int32 SortRowNumber { get; set; }
    public DateTime CreatedDate { get; set; }
    public String CreatedBy { get; set; }
    public DateTime UpdatedDate { get; set; }
    public String UpdatedBy { get; set; }
    public Int32 DeletedDate { get; set; }
    public String eCrewID { get; set; }
    public Int32 EntityTypeID { get; set; }
}

运行一个简单的代码:

   var repo = new SimpleRepository("kiss", SimpleRepositoryOptions.None);
   var users = repo.All<Users>();
   gvUsers.DataSource = users;
   gvUsers.DataBind();

产生错误:

System.Data.SqlClient.SqlException was unhandled by user code
  Message="Invalid object name 'Users'."
  Source=".Net SqlClient Data Provider"
  ErrorCode=-2146232060
  Class=16
  LineNumber=1
  Number=208
  Procedure=""
  Server="(local)\\SQLEXPRESS"
  State=1
  StackTrace:
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
       at System.Data.SqlClient.SqlDataReader.get_MetaData()
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
       at System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
       at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
       at SubSonic.DataProviders.DbDataProvider.ExecuteReader(QueryCommand qry)
       at SubSonic.Linq.Structure.DbQueryProvider.Execute[T](QueryCommand`1 query, Object[] paramValues)
       at lambda_method(ExecutionScope )
       at SubSonic.Linq.Structure.DbQueryProvider.Execute(Expression expression)
       at SubSonic.Linq.Structure.QueryProvider.System.Linq.IQueryProvider.Execute(Expression expression)
       at SubSonic.Linq.Structure.Query`1.System.Collections.IEnumerable.GetEnumerator()
       at System.Web.UI.WebControls.PagedDataSource.GetEnumerator()
       at System.Web.UI.WebControls.GridView.CreateAutoGeneratedColumns(PagedDataSource dataSource)
       at System.Web.UI.WebControls.GridView.CreateColumns(PagedDataSource dataSource, Boolean useDataSource)
       at System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding)
       at System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data)
       at System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data)
       at System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback)
       at System.Web.UI.WebControls.DataBoundControl.PerformSelect()
       at System.Web.UI.WebControls.BaseDataBoundControl.DataBind()
       at System.Web.UI.WebControls.GridView.DataBind()
       at web_subsonic._Default.Page_Load(Object sender, EventArgs e) in C:\scr\wcsf_playground\Modules\web_subsonic\web_subsonic\Default.aspx.cs:line 25
       at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
       at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
       at System.Web.UI.Control.OnLoad(EventArgs e)
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

2 个答案:

答案 0 :(得分:1)

您登录的默认架构是什么?不幸的是,你的对象无法知道你正在使用什么模式 - 这是app ---&gt; db记住,所以如果你有一个单独的模式,你应该使用默认使用该模式的登录。

答案 1 :(得分:0)

有两个选项

首先,获取最新的源代码,并修改源代码

  1. 找到SchemaAttributes.cs,添加代码:

    [AttributeUsage(AttributeTargets.Class)] 公共类SubSonicTableSchemaAttribute:Attribute {     public SubSonicTableSchemaAttribute(字符串架构)     {         Schema = schema;     }

    public string Schema { get; set; }
    

    }

  2. 将SubSonicTableSchemaAttribute绑定到用户类

    [SubSonic.SqlGeneration.Schema.SubSonicTableSchema( “吻”)] 公共类用户{...}

  3. 查找Objects.cs文件,将代码添加到“public static ITable ToSchemaTable(此Type type,IDataProvider provider)”方法

    var typeAttributes = type.GetCustomAttributes();         foreach(typeAttributes中的var typeAtt)         {             如果(typeAtt.ToString()。等于( “SubSonic.SqlGeneration.Schema.SubSonicTableSchemaAttribute”))             {                 var schema =(SubSonicTableSchemaAttribute)typeAtt;                 result.SchemaName = schema.Schema;             }         }

  4. 其次,看看我的演示: Use subsonic 3.0 SimpleRepository to a existing database