tags:

views:

433

answers:

2

I am using sql server 2008, to follow the latest convention I used new schema other than [dbo].[tablename] which is now look like this [newdbo].[tablename]. The problem now, SimpleRepository could not locate [newdbo].[tablename], I assumed it is looking for [dbo] rather than [newdbo], since my class is define as:

here's my Table: Schema/owner is "kiss"

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

and here is my class:

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; }
}

running a simple code:

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

yield an error:

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:
+1  A: 

What's the default schema for your login? Unfortunately there's no way your object will know what schema you're working with - this is app ---> db remember, so if you have a separate schema you should use a login which uses that schema by default.

Rob Conery
No Body
A: 

There are two options

First, get the latest source code, and modify the souce code

  1. Find the SchemaAttributes.cs, add code:

    [AttributeUsage(AttributeTargets.Class)] public class SubSonicTableSchemaAttribute : Attribute { public SubSonicTableSchemaAttribute(string schema) { Schema = schema; }

    public string Schema { get; set; }
    

    }

  2. Bind the SubSonicTableSchemaAttribute to User Class

    [SubSonic.SqlGeneration.Schema.SubSonicTableSchema("kiss")] public class User{...}

  3. Find Objects.cs file, Add code to the "public static ITable ToSchemaTable(this Type type, IDataProvider provider)" Method

    var typeAttributes = type.GetCustomAttributes(); foreach (var typeAtt in typeAttributes) { if(typeAtt.ToString().Equals("SubSonic.SqlGeneration.Schema.SubSonicTableSchemaAttribute")) { var schema = (SubSonicTableSchemaAttribute) typeAtt; result.SchemaName = schema.Schema; } }

Second, have a look at my demo: http://stackoverflow.com/questions/1164200/a-question-about-subsonic-3-0-simplerepository

Nick Yao
Thanks Nick,how can I tell SimpleReposity that not all my properties on my entity will be use in updating nor inserting?like field such as "CreatedDate" which is define on my table with GETDATE() as default value.And how can push records on SimpleRepository Parent/Child relation ship, where in I need parent auto generated ID to be used by child?
No Body
Default values won't work on inserts because your object will set the value first. You should see the link below:http://stackoverflow.com/questions/1171025/subsonic-3-0-the-sqlserver-default-value-doesnt-work
Nick Yao
how can push records on SimpleRepository Parent/Child relation ship, where in I need parent auto generated ID to be used by child?
No Body
I'd seed my answer on this link:http://subsonicproject.com/docs/Can_SubSonic_Scale
No Body