New Posts New Posts RSS Feed: Index was outside the bounds of the array.
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Index was outside the bounds of the array.

 Post Reply Post Reply
Author
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Topic: Index was outside the bounds of the array.
    Posted: 21-Sep-2010 at 6:04pm
Cool.  Glad you found it!
Back to Top
sky40627 View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Oct-2009
Posts: 34
Post Options Post Options   Quote sky40627 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Sep-2010 at 10:52pm
Hi, I found the problem.
 
When creating entities in the edmx instead of in the database, the languageId is not set as a property and the Referential Constraint is not set, which is causing the error.
 
Once I took care of those 2 things all went fine.
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 20-Sep-2010 at 3:05pm
Yes, you need to create the EDMX with IncludeForeignKeys set to 'on'.  Are you deleting any properties in the model?  e.g. if Customer has a LanguageID property, the LanguageID should be a property on the Customer entity (some people want to delete the underlying foreign keys).

If you can't figure it out, post the EDMX and we'll take a look.

Back to Top
sky40627 View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Oct-2009
Posts: 34
Post Options Post Options   Quote sky40627 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Sep-2010 at 3:32am
sorry but i am here again
 
  #error DevForce requires that foreign key columns be included in the model. This must be set when the EDMX is first created. If you are upgrading from DevForce 2009, you cannot use the old model and should recreate it using the Entity Framework for .NET 4.0.  The following associations were not set up with foreign key associations enabled: LanguageCustomer
 
since i upgraded to 6.0.5 i get this error
 
but my edmx was create new and with IncludeForeignKeys chipped on
 
Back to Top
sky40627 View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Oct-2009
Posts: 34
Post Options Post Options   Quote sky40627 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Sep-2010 at 3:26am
in my edmx the IncludeForeignKeysInModel=True
so i removed the errorline generate by defvorce
 
<DesignerInfoPropertySet>
        <DesignerProperty Name="ValidateOnBuild" Value="true" />
        <DesignerProperty Name="EnablePluralization" Value="True" />
        <DesignerProperty Name="IncludeForeignKeysInModel" Value="True" />
      </DesignerInfoPropertySet>
 
these are my Customer properties
 
   #region Properties

    #region Id property

    /// <summary>Gets or sets the Id. </summary>
    [Bindable(true, BindingDirection.TwoWay)]
    [Editable(true)]
    [Display(Name="Id", AutoGenerateField=true)]
    [IbVal.RequiredValueVerifier( ErrorMessageResourceName="Customer_Id")]
    [DataMember]
    public int Id {
      get { return PropertyMetadata.Id.GetValue(this); }
      set { PropertyMetadata.Id.SetValue(this, value); }
    }
    #endregion Id property

    #region Name property

    /// <summary>Gets or sets the Name. </summary>
    [Bindable(true, BindingDirection.TwoWay)]
    [Editable(true)]
    [Display(Name="Name", AutoGenerateField=true)]
    [IbVal.RequiredValueVerifier( ErrorMessageResourceName="Customer_Name")]
    [DataMember]
    public string Name {
      get { return PropertyMetadata.Name.GetValue(this); }
      set { PropertyMetadata.Name.SetValue(this, value); }
    }
    #endregion Name property
    #endregion Properties

    #region Navigation properties

    #region Language property

    /// <summary>Gets or sets the Language. </summary>
    [Bindable(false)]
    [Display(Name="Language", AutoGenerateField=false)]
    [DataMember]
    [IbEm.RelationProperty("LanguageCustomer", IbEm.QueryDirection.ToRole1)]
    public Language Language {
      get { return PropertyMetadata.Language.GetValue(this); }
      set { PropertyMetadata.Language.SetValue(this, value); }
    }
    #endregion Language property
    #endregion Navigation properties

I hope you have enough information to help me with my problem
Back to Top
sky40627 View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Oct-2009
Posts: 34
Post Options Post Options   Quote sky40627 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Sep-2010 at 3:18am
when i do an include as here below it works
 
            //foreach (var item in manager.Customers)
            //{
            //    MessageBox.Show(item.Language.Name);
            //}
           var qry = manager.Customers
                .Include(ClassLibrary1.Customer.PathFor(c=>c.Language));
            foreach (var item in qry)
            {
                MessageBox.Show(item.Language.Name);
            }
Back to Top
sky40627 View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Oct-2009
Posts: 34
Post Options Post Options   Quote sky40627 Quote  Post ReplyReply Direct Link To This Post Posted: 20-Sep-2010 at 2:42am
I did the upgrade to 6.0.5 i was working with 6.0.4
 
I deleted my edmx and the .tt ....
 
I recreated a new edmx from a blank database and made sure the foreign key was "on"
 
still the same error
 
What exactly do you mean by real properties and not hidden ?
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post Posted: 17-Sep-2010 at 4:31pm
Make sure that you are using DevForce 6.0.5 as we fixed a bug (B1537) that had this symptom.  Also, confirm that the foreign keys are real properties on the model and are not "hidden" in the edmx.

Back to Top
sky40627 View Drop Down
Newbie
Newbie
Avatar

Joined: 06-Oct-2009
Posts: 34
Post Options Post Options   Quote sky40627 Quote  Post ReplyReply Direct Link To This Post Posted: 17-Sep-2010 at 10:47am

I created a new test app

in the edmx i created two entities "Customer" and "Language" adding an association between the two so Customer has a language and Language has Customers

then I generated the sql to create the database

-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 09/17/2010 19:39:39
-- Generated from EDMX file: c:\users\koen.skn\documents\visual studio 2010\Projects\WindowsFormsApplication1\ClassLibrary1\Model1.edmx
-- --------------------------------------------------
SET QUOTED_IDENTIFIER OFF;
GO
USE [test];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO
-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------
IF OBJECT_ID(N'[dbo].[FK_LanguageCustomer]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Customers] DROP CONSTRAINT [FK_LanguageCustomer];
GO
-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------
IF OBJECT_ID(N'[dbo].[Customers]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Customers];
GO
IF OBJECT_ID(N'[dbo].[Languages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Languages];
GO
-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------
-- Creating table 'Customers'
CREATE TABLE [dbo].[Customers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Language_Id] int  NOT NULL
);
GO
-- Creating table 'Languages'
CREATE TABLE [dbo].[Languages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NOT NULL
);
GO
-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------
-- Creating primary key on [Id] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [PK_Customers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating primary key on [Id] in table 'Languages'
ALTER TABLE [dbo].[Languages]
ADD CONSTRAINT [PK_Languages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------
-- Creating foreign key on [Language_Id] in table 'Customers'
ALTER TABLE [dbo].[Customers]
ADD CONSTRAINT [FK_LanguageCustomer]
    FOREIGN KEY ([Language_Id])
    REFERENCES [dbo].[Languages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
-- Creating non-clustered index for FOREIGN KEY 'FK_LanguageCustomer'
CREATE INDEX [IX_FK_LanguageCustomer]
ON [dbo].[Customers]
    ([Language_Id]);
GO
-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------

In my app I do this

using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        ClassLibrary1.Model1Container manager =
            ClassLibrary1.Model1Container.DefaultManager;
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            ClassLibrary1.Language lang = new ClassLibrary1.Language();
            lang.Name = "Dutch";
            lang.EntityAspect.AddToManager();
            ClassLibrary1.Customer customer = new ClassLibrary1.Customer();
            customer.Name = "Koen";
            customer.Language = lang;
            customer.EntityAspect.AddToManager();
            manager.SaveChanges();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            foreach (var item in manager.Customers)
            {
                MessageBox.Show(item.Language.Name);
            }
        }
    }
}

I click button 1 and then button 2 and i get a messagebox showing my language name

i close the app and then the debugger stops at the Langiage getter in the Customer:

 #region Language property

    /// <summary>Gets or sets the Language. </summary>
    [Bindable(false)]
    [Display(Name="Language", AutoGenerateField=false)]
    [DataMember]
    [IbEm.RelationProperty("LanguageCustomer", IbEm.QueryDirection.ToRole2)]
    public Language Language {
      get { return PropertyMetadata.Language.GetValue(this); }
      set { PropertyMetadata.Language.SetValue(this, value); }
    }
    #endregion Language property
    #endregion Navigation properties

giving this error : Index was outside the bounds of the array.

Can someone please help us out here, thx

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down