Subsonic 亚音速3.0.0.2/3 |简单假设

Subsonic 亚音速3.0.0.2/3 |简单假设,subsonic,Subsonic,我使用的是sql server 2008,为了遵循最新的约定,我使用了新模式,而不是[dbo].[tablename],它现在看起来像这样的[newdbo].[tablename]。现在的问题是,SimpleRepository无法定位[newdbo].[tablename],我假设它正在查找[dbo]而不是[newdbo],因为我的类定义为: 这是我的表:Schema/owner是“kiss” 这是我的班级: public class Users { public Int32 ID {

我使用的是sql server 2008,为了遵循最新的约定,我使用了新模式,而不是[dbo].[tablename],它现在看起来像这样的[newdbo].[tablename]。现在的问题是,SimpleRepository无法定位[newdbo].[tablename],我假设它正在查找[dbo]而不是[newdbo],因为我的类定义为:

这是我的表:Schema/owner是“kiss”

这是我的班级:

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();

您登录的默认模式是什么?不幸的是,您的对象无法知道您正在使用的模式-这是app-->db Memory,因此如果您有单独的模式,您应该使用默认使用该模式的登录名。

有两个选项

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

  • 查找SchemaAttributes.cs,添加代码:

    [AttributeUsage(AttributeTargets.Class)] 公共类SubNicTableSchemaAttribute:属性 { 公共子表SchemaAttribute(字符串架构) { 模式=模式; }

    }

  • 将SubNicTableSchemaAttribute绑定到用户类

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

  • 查找Objects.cs文件,将代码添加到“publicstaticitabletoschematable(此类型,IDataProvider提供程序)”方法中

    var typeAttributes=type.GetCustomAttributes(); foreach(typeAttributes中的var typeAtt) { if(typeAtt.ToString().Equals(“SubSonic.SqlGeneration.Schema.SubSonicTableSchemaAttribute”)) { var schema=(subnictableschemaattribute)typeAtt; result.SchemaName=schema.schema; } }

  • 第二,看看我的演示:

    我尝试从[kiss]重命名模式/所有者。至[dbo]。“砰”的一声,开始起作用了。但我希望它是[吻]。作为架构/所有者。感谢现在的工作,我的用户默认模式是“dbo”。现在是扩展问题。我需要关联/连接/查询模式为“dbo”的对象。“kiss.”与“dbo.”相关=(“我们正在混合新旧”谢谢Nick,我怎么能告诉SimpleRepositiy我的实体上的所有属性都不会用于更新或插入?像“CreatedDate”这样的字段,它在我的表上用GETDATE()定义)作为默认值。如何在SimpleRepository父/子关系上推送记录,其中我需要父自动生成的ID供子级使用?默认值在插入时不起作用,因为您的对象将首先设置值。您应该看到下面的链接:如何在SimpleRepository父/子关系上推送记录,其中在eed父级自动生成的ID将由子级使用?我将在以下链接中添加我的答案:
       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: 
    
    public string Schema { get; set; }