This project has moved and is read-only. For the latest updates, please go here.

issue with creating object from View

Jan 26, 2012 at 7:29 PM

Hi

I get error when I try to create an object (Root, readonlylist) using a view.

Validation: Business
* Warning:
Generation settings: 'Utility classes folder' will be ignored (separate namespaces in folders is set).

Passed.
Validation: DalInterface
Passed.
Validation: DalObject
Passed.

vSchoolSearchDetails:
 File: D:\Users\Richard\Development\VS2010\WinApps\AbracaAdmin\AbracaAdmin.Business\vSchoolSearchDetails.Designer.cs
* Warning:
vSchoolSearchDetails; root objects must have a criteria with GetOptions.Factory set.

 File: D:\Users\Richard\Development\VS2010\WinApps\AbracaAdmin\AbracaAdmin.Dal\IvSchoolSearchDetailsDal.Designer.cs
* Warning:
vSchoolSearchDetails; root objects must have a criteria with GetOptions.Factory set.

 File: D:\Users\Richard\Development\VS2010\WinApps\AbracaAdmin\AbracaAdmin.DalAdo\vSchoolSearchDetailsDal.Designer.cs
* * * Error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Stack Trace:
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at CslaGenerator.CodeGen.CslaTemplateHelperCS.GetCommand(CslaObjectInfo info, String commandText)
   at _CodeSmithTemplate.EditableRoot_DalObject_cst.__RenderMethod1(TextWriter writer, Control control)
   at CodeSmith.Engine.Control.RenderChildren(TextWriter writer)
   at CodeSmith.Engine.CodeTemplate.Render(TextWriter writer)
   at CslaGenerator.CodeGen.AdvancedGenerator.DoGenerateDal(CslaObjectInfo objInfo, GenerationStep step)


Done
DataPortalHookArgs classe: already exists.
IDalManagerAbracaAdmin classe: already exists.
DalFactoryAbracaAdmin classe: already exists.
DataNotFoundException classe: already exists.
DalManagerAbracaAdmin classe: already exists.

Object warnings: 2 objects.

Classes: 3 generated. 1 failed.
Stored Procs: 0 generated. 0 failed.

Can you advise, thanks

Richard

 

Jan 28, 2012 at 10:27 AM

Hi Richard,

Sorry for taking so long to reply but have been working long hours. First of all try to get rid of all the warnings. If the error persist, it must related to the views. i'am not sure all parts of the code can handle views instead of tables.

Jan 29, 2012 at 7:39 PM

Hi Tiago

one of the reasons I have moved from using Blake's templates (codesmith) was that cslagen used to be able to create bo's from views and procedures - is this a feature that will be added at some point - (I do appreciate the time and effort you put in).  Alternatively how do you handle building a business object where the table has inner joins to other tables??

 

Jan 29, 2012 at 8:07 PM
Edited Jan 29, 2012 at 8:07 PM
zen8019 wrote:

(...) cslagen used to be able to create bo's from views and procedures - is this a feature that will be added at some point

Yes it. I'm afraid I broke it inadvertently. I'm not very familiar with Views but there are some restrictions concerning INSERT and UPDATE. I checked this article http://jagbarcelo.blogspot.com/2006/09/identity-columns-in-view-treated-as.html

Two questions:

1) Views were used only as data source for ReadOnly objects and collections?

2) Stored Procedures were used only as data source for ReadOnly objects and collections?

 

zen8019 wrote:

Alternatively how do you handle building a business object where the table has inner joins to other tables?? 

 I'am afraid I'm not quite following you. What is a table with "inner joins" to other tables? Are you referring to foreign keys?

Jan 29, 2012 at 8:09 PM
tiago wrote:

Hi Richard,

Sorry for taking so long to reply but have been working long hours. First of all try to get rid of all the warnings. If the error persist, it must related to the views. i'am not sure all parts of the code can handle views instead of tables.


If the problem doesn't go away after cleaning the warnings, you must send me a database schema and the project file so I can debug the issue.

Jan 30, 2012 at 9:51 AM

Hi

yes, the views and procs are for read only objects/collections.

When I say inner join - maybe I mean foreign key e.g.

SELECT     dbo.tblActualEvents.SchoolID,  dbo.tblActualEvents.DateOfEvent, dbo.tblEvents.Event FROM         dbo.tblActualEvents INNER JOIN                      dbo.tblEvents ON dbo.tblActualEvents.ID = dbo.tblEvents.ID

A view will show one of more tables linked/related via foreign keys - how can I achieve this using cslagenfork if I can't have a view as the underlying data source.

Richard

 

Jan 31, 2012 at 12:34 AM
Edited Jan 31, 2012 at 12:37 AM

Hi Richard,

Assuming there is a Foreign Key between tblActualEvents.ID and tblEvents.ID, all you have to do is to define an object with Value Properties:

  • SchoolID
  • DateOfEvent
  • Event

and point the BD Bind Column of these Value Properties to

  • tblActualEvents.SchoolID
  • tblActualEvents.DateOfEvent
  • tblEvents.Event

After choosing the appropriate table/columns, the actual DB Bind Column will read

  • SchoolID (tblActualEvents)
  • DateOfEvent (tblActualEvents)
  • Event (tblEvents)

This is the most common scenario and since this is a ReadOnly object or collection, you don't need to care about Data Access Behaviour property and can leave it ReadWrite.

You shouldn't need to use FK Constraint property except on quite advanced scenarios, like when there are several ForeignKey relations between two tables.

Having a second look, I noticed that your SQL statement has no WHERE clause and I'm not sure SchoolID is the PrimaryKey of your BO. There should be a DBProvidedPK or a UserProvidedPK on every object. May be not on this case, since you don't need a WHERE clause. Never tried that way but maybe it works for a ReadOnlyCollection that fetches the full collection.

Jan 31, 2012 at 10:47 PM

Hi

Thanks, will look into

R

From: tiago [email removed]
Sent: 31 January 2012 00:34
To: richard@rgsoft.co.uk
Subject: Re: issue with creating object from View [cslagenfork:287531]

From: tiago

Hi Richard,

Assuming there is a Foreign Key between tblActualEvents.ID and tblEvents.ID, all you have to do is to define an object with Value Properties:

  • SchoolID
  • DateOfEvent
  • Event

and point the BD Bind Column of these Value Properties to

  • tblActualEvents.SchoolID
  • tblActualEvents.DateOfEvent
  • tblEvents.Event

After choosing the appropriate table/columns, the actual DB Bind Column will read

  • SchoolID (tblActualEvents)
  • DateOfEvent (tblActualEvents)
  • Event (tblEvents)

This is the most common scenario and since this is a ReadOnly object or collection, you don't have to care about Data Access Behaviour property and can leave it ReadWrite.

You shouldn't need to use FK Constraint property except on quite advanced scenarios, like when there are several ForeignKey relations between two tables.

Having a second look, I noticed that your SQL statement has no WHERE clause and I'm not sure SchoolID is the PrimaryKey of your BO. There should be a DBProvidedPK or a UserProvidedPK on every object. May be not on this case, since you don't need a WHERE clause. Never tried that way but maybe it works for a ReadOnlyCollection that fetches the full collection.

No virus found in this message.
Checked by AVG - www.avg.com
Version: 2012.0.1901 / Virus Database: 2109/4778 - Release Date: 01/31/12

Feb 14, 2012 at 12:36 AM

Hi Richard,

Did CslaGenFork generate the SProc as it should?