The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Problem wiht PrimaryKey

Last post 04-24-2007, 4:26 AM by David.Parsons. 4 replies.
Sort Posts: Previous Next
  •  04-23-2007, 7:45 AM 1968

    Problem wiht PrimaryKey

    The table Setup has 3 fields in Primary Key (Libro,Seccion,Almacen).

     In the  MyGeneration (1.2.0.6) MyMeta Brower the fields in

    Setup  - Indexes - PrimaryKey - Columns = (Libro,Seccion,Almacen). Big Smile

    But in

    Setup - PrimaryKeys =  (Almacen,Seccion,Libro). Tongue Tied

    The method generated in EntitySpaces 2007 Beta v0.0415  master template is: 

    Code:
    		#region LoadByPrimaryKey
    
    		public virtual bool LoadByPrimaryKey(System.String almacen, System.String seccion, System.String libro) Tongue Tied
    		{
    			if(this.es.Connection.SqlAccessType == esSqlAccessType.DynamicSQL)
    				return LoadByPrimaryKeyDynamic(almacen, seccion, libro);
    			else
    				return LoadByPrimaryKeyStoredProcedure(almacen, seccion, libro);
    		}
    	
    		/// <summary>
    		/// Loads an entity by primary key
    		/// </summary>
    		/// <remarks>
    		/// EntitySpaces requires primary keys be defined on all tables.
    		/// If a table does not have a primary key set,
    		/// this method will not compile.
    		/// </remarks>
    		/// <param name="sqlAccessType">Either esSqlAccessType StoredProcedure or DynamicSQL</param>
    		public virtual bool LoadByPrimaryKey(esSqlAccessType sqlAccessType, System.String almacen, System.String seccion, System.String libro)
    		{
    			if (sqlAccessType == esSqlAccessType.DynamicSQL)
    				return LoadByPrimaryKeyDynamic(almacen, seccion, libro);
    			else
    				return LoadByPrimaryKeyStoredProcedure(almacen, seccion, libro);
    		}
    	
    		private bool LoadByPrimaryKeyDynamic(System.String almacen, System.String seccion, System.String libro)
    		{
    			esSetupQuery query = this.GetDynamicQuery();
    			query.Where(query.Almacen == almacen, query.Seccion == seccion, query.Libro == libro);
    			return query.Load();
    		}
    	
    		private bool LoadByPrimaryKeyStoredProcedure(System.String almacen, System.String seccion, System.String libro)
    		{
    			esParameters parms = new esParameters();
    			parms.Add("Almacen",almacen);			parms.Add("Seccion",seccion);			parms.Add("Libro",libro);
    			return this.Load(esQueryType.StoredProcedure, this.es.spLoadByPrimaryKey, parms);
    		}
    		#endregion

     This is not correct

    public virtual bool LoadByPrimaryKey(System.String almacen, System.String seccion, System.String libro) Sad

    Thanks


     

     

     

     

     

     

  •  04-23-2007, 11:10 AM 1979 in reply to 1968

    Re: Problem wiht PrimaryKey

    Please also remember to post the version of EntitySpaces you are using. Are you saying this changed recently in a new version of EntitySpaces or just that they are being generated in a different order than the order you have defined in your database?

    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  04-23-2007, 11:24 AM 1980 in reply to 1968

    Re: Problem wiht PrimaryKey

    1) We have a test table for our unit tests with a composite PK:

    Code:
    CREATE TABLE [dbo].[Customer](
    	[CustomerID] [char](5) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    	[CustomerSub] [char](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    	[CustomerName] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    	[DateAdded] [datetime] NOT NULL,
    	[Active] [bit] NOT NULL CONSTRAINT [DF__DbaMgr_Tm__Activ__1BFD2C07]  DEFAULT ((1)),
    	[ConcurrencyCheck] [timestamp] NOT NULL,
    	[Manager] [int] NOT NULL,
    	[StaffAssigned] [int] NULL,
    	[UniqueID] [uniqueidentifier] NULL CONSTRAINT [DF_Customer_UniqueID]  DEFAULT (newid()),
    	[Notes] [text] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    	[CreditLimit] [money] NULL,
    	[Discount] [decimal](18, 4) NULL,
     CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED 
    (
    	[CustomerID] ASC,
    	[CustomerSub] ASC
    )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    

    Looking in SQL Server Management Studio, the first two columns in the table are CustomerID, CustomerSub
    The PrimaryKey lists CustomerID, CustomerSub
    There is a clustered index - CustomerID, CustomerSub

    In MyGeneration MyMeta Browser:
    The first two columns listed are CustomerID, CustomerSub
    Indexes - PrimaryKey - Columns = CustomerID, CustomerSub
    PrimaryKeys = CustomerID, CustomerSub

    2) EntitySpaces just takes the PKs in the order listed in MyGeneration to create the methods.

    3) Which database are you using? When you look at the table, PK, and indexes in your database administrator, are they defined consistently?

    4) The bottom line is that I'm not sure I understand the problem. Huh? As long as EntitySpaces is internally consistent in the parameter ordering in its methods, and does not arbitrarily generate a different order from one release to the next, why is the order important? Are you getting compile errors? a runtime exception? for which version of Entityspaces?


    David Neal Parsons
    www.entityspaces.net
  •  04-24-2007, 12:42 AM 1981 in reply to 1980

    Re: Problem wiht PrimaryKey

    Hi

    The Database is = MSACCESS.

    The MyGeneration version is = 1.2.0.6.

    The EntitySpaces version is = EntitySpaces 2007 Beta v0.0415. 

    This is the table schema = 

    CREATE TABLE [Setup]
    (
    [Libro] VARCHAR (10)  NOT NULL,
    [Seccion] VARCHAR (10)  NOT NULL,
    [Almacen] VARCHAR (10)  NOT NULL,
    [Linea] INT,
    [UltLinea] INT,
    [Operario] VARCHAR (20)
    );

    ALTER TABLE [Setup]
    ADD
    CONSTRAINT [Primary Key] PRIMARY KEY ([Libro] ,[Seccion] ,[Almacen]);

    El problem is the order listed =

    This is not correct = 

    In MyMeta Brower the fields = Setup - PrimaryKeys =  (Almacen,Seccion,Libro).

    In Method = public virtual bool LoadByPrimaryKey(System.String almacen, System.String seccion, System.String libro) Tongue Tied

     It should be =

    In MyMeta Brower the fields = Setup - PrimaryKeys =  (Libro,Seccion,Almacen).

    public virtual bool LoadByPrimaryKey(System.String libro, System.String seccion,System.String almacen,)

     

  •  04-24-2007, 4:26 AM 1982 in reply to 1981

    Re: Problem wiht PrimaryKey

    Yes, for our Access test db, the composite PrimaryKey columns are listed in reverse order in MyGeneration. I've reported the issue in the MyGeneration forums. I added a ticket to our issue tracking system to follow through. We could modify our templates with a special case for Access, but we have a special "in" with one of the MyGeneration developer's Wink It would be best to get it fixed there. Thx for alerting us.

    http://www.mygenerationsoftware.com/phpbb2/viewtopic.php?t=2740

    Other than the fact that it is confusing, it should not affect the operation of EntitySpaces. Once a fix is in place and you regenerate, you will have to fix any place in code that uses LoadByPrimaryKey for that table. Since, in your case, all three are VARCHAR/String, you will not get compile errors. So, you should be on the lookout for that fix in our release notes for future releases, and make the change by searching your source code files.


    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML