This is a migrated thread and some comments may be shown as answers.

Can't create managed one-to-many collection

17 Answers 218 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Denis Vulinovich
Top achievements
Rank 1
Denis Vulinovich asked on 13 Aug 2009, 01:39 AM
I'm trying to use the Forward Mapping wizard to create a managed one-to-many relationship between Company (one) and Person (many) objects. But the "Managed collection" option on the wizard is disabled and I can't select it.

Here's the relevant code from the Company and Person classes:
    [Telerik.OpenAccess.Persistent()] 
    public class Company 
    { 
        private IList<Person> _persons = new List<Person>(); 
 
        [FieldAlias( "_persons" )]
        public IList<Person> Persons
        {
            get { return _persons; }
        }

       public void AddPerson( Person person ) 
        { 
            _persons.Add( person ); 
        } 
 
        public void RemovePerson( Person person ) 
        { 
            _persons.Remove( person ); 
        } 
    } 
 
    [Telerik.OpenAccess.Persistent()] 
    public class Person 
    { 
        private Company _company; 

        [FieldAlias( "_company" )]
        public Company Company
        {
            get { return _company; }
        }
    } 
 
In the database it creates a company_person table with the id from each class, and it updates this table whenever I call the Company's AddPerson() and RemovePerson() methods. But the Person's _company field is always null.

Here are the relevant parts of App.config:
          <class name="Company"
            <field name="_persons"
              <collection> 
                <extension key="db-link-table" /> 
              </collection> 
            </field> 
          </class> 
          <class name="Person"
 
          </class> 
 
 
It's interesting that the Person class has no key for its _company field.

I've tried disabling OpenAccess in this project, deleting App.config and then starting from scratch again, but I still get the same result.

17 Answers, 1 is accepted

Sort by
0
Denis Vulinovich
Top achievements
Rank 1
answered on 13 Aug 2009, 08:24 AM
I've just noticed that the help topic "Forward Mapping Wizard - One to Many Reference Mapping - Without Join Table" shows a screen shot with a "Managed Collection" checkbox just below "Default fetch group". But my software doesn't have that option. I'm using Express version 2009.2.701.5.
0
Jan Blessenohl
Telerik team
answered on 13 Aug 2009, 08:27 AM
Hi Denis Vulinovich,
The _persons collection is mapped to a join table by default. It has nothing to do with the reference _company. You have to tell OpenAccess that this is a 1:n and that _company is the 1 part.

To do so please open the forward mapping dialog and select Company->_persons node. Now switch off the Join Table check boy and select _company in the Inverse Field ComboBox. Now you can switch on Manager Collection and it will work.



Sincerely yours,
Jan Blessenohl
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 13 Aug 2009, 08:55 AM
Thanks, Jan, that worked.

With my previous comment, I was actually looking at a different pair of classes where the "n" class didn't have the reverse field. So that's probably why the Managed Collection checkbox didn't appear.

Thanks again for your help.

Denis
0
Iftekhar Ivaan
Top achievements
Rank 1
answered on 17 Aug 2009, 01:04 AM
Hi,

If I do this, it works fine. But in the database I do not see and one to many link in the database diagrame view. It does not shows any link between two tables. If we we many to many we can see the link. I am using SQL server 2005.

How can I see the link in the database diagrame. It is easy to understand the table relation.

Thanks
0
IT-Als
Top achievements
Rank 1
answered on 17 Aug 2009, 09:41 AM
Hi Iftekhar,

Please check if you on the many side of the association have one of the "Generate foreign key...." checked. Doing so, will get you a foreign key contraint on the many side table that references the one side table.
And foreign key constraints should be recognizable in the various tools

Regards

Henrik
0
Iftekhar Ivaan
Top achievements
Rank 1
answered on 18 Aug 2009, 04:42 AM
Hi,

I have done that and it is not still working.
0
PetarP
Telerik team
answered on 18 Aug 2009, 11:19 AM
Hello Iftekhar Ivaan,

By default Telerik OpenAccess ORM uses algorithms to decide weather a foreign key constraint makes sense or not. In your case you can use this setting in the backend configuration to manually override our algorithm:
<dbNullForeignKey>true</dbNullForeignKey> 
This will create your foreign key constraint and you will see the connection in your diagram. Let us know if the following solution works for you.

Sincerely yours,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Iftekhar Ivaan
Top achievements
Rank 1
answered on 19 Aug 2009, 01:10 AM
Hi,

Which section I need to copy this.

Thanks
0
PetarP
Telerik team
answered on 19 Aug 2009, 08:34 AM
Hi Iftekhar Ivaan,

In the backend configuration node that is located in the app.config file. To give you more clear example it should look something like this:
 <backendconfigurations> 
      <backendconfiguration id="mssqlConfiguration" backend="mssql"
        <dbNullForeignKey>true</dbNullForeignKey> 
        <mappingname>mssqlMapping</mappingname> 
      </backendconfiguration> 
    </backendconfigurations> 


Best wishes,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 19 Aug 2009, 06:30 PM
I have another problem with my original managed one-to-many relationship between Company and Person objects. In the Forward Mapping wizard, on the Person._company field I've selected the option "Throw an exception on commit if field is null", but the database doesn't have a NOT NULL constraint on the same column. If I add one, it's deleted the next time I build the project.

It's only happened since I've added both classes to an inheritance hierarchy where they both derive from the same base class. This is from App.config:
          <class name="Company">
            <extension key="db-inheritance" value="vertical" />
            <extension key="db-table-name" value="company" />
            <field name="_persons">
              <collection>
                <extension key="inverse" value="_company" />
                <extension key="managed" value="true" />
              </collection>
            </field>
          </class>
          <class name="Person">
            <field name="_company" null-value="exception">
              <extension key="db-column">
                <extension key="db-column-name" value="Company" />
              </extension>
            </field>
            <extension key="db-inheritance" value="vertical" />




          </class> 

 

0
Zoran
Telerik team
answered on 24 Aug 2009, 03:22 PM
Hello Denis Vulinovich,

This is a result of the way Telerik OpenAccess ORM handles these scenarios. When you have a field which has the "Throw an exception on commit if field is null" option switched on, the runtime makes the check in-memory and does not hit the database server at all before throwing the exception. That is why this constraint is not visible in the database.

Regards,
Zoran
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 24 Aug 2009, 07:20 PM
Hi Zoran,

Since I derived Person and Company from another class, my tests have been failing because I'm no longer getting the Telerik.OpenAccess.Exceptions.DataStoreException that it used to throw when a Person was created without a Company. That's when I discovered the missing database constraint.

Regards,
Denis
0
PetarP
Telerik team
answered on 27 Aug 2009, 01:12 PM
Hello Denis Vulinovich,

When you specify a field to "Throw an exception on commit if field is null" no constrains are created in the database but the field is being checked at runtime. If the field is null, the object is not stored but an exception is thrown. It seems we have some runtime problems with this feature and that is why you are not seeing the exception. Please find your Telerik points updated for reporting this bug.

Greetings,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 01 Jan 2010, 02:50 AM
Hi Petar,

I'm just wondering when this bug is going to be fixed?

I'm using OpenAccess version 2009.3.1104.2, and no exception is thrown when the field is null.

Thanks,
denis
0
PetarP
Telerik team
answered on 05 Jan 2010, 09:35 AM
Hello Denis Vulinovich,

You can set this option via the wizard only for forward mapping scenarios. The equivalent of this constraint in reverse mapping would be if a column is marked as non nullable. The check itself used to be performed in-memory but now it is pushed to the server.

Regards,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Denis Vulinovich
Top achievements
Rank 1
answered on 07 Jan 2010, 06:56 AM
Hi Petar,

I'm using the Forward Mapping wizard and I select the option to throw an exception if the field is null, as shown in attached screen dump. But I get no exception if I create a Person object without a Company.

Regards,
Denis
0
PetarP
Telerik team
answered on 08 Jan 2010, 11:03 AM
Hello Denis,

Was your model originally forward mapped or it was reverse mapped? There is a good possibility that the data in your column is in conflict with the constraint we are trying to create and that is why the constraint is missing even after you check the box. Can you see if there are entries in your database that have null value for the  company column? If so, please change them to non-null values and try again. This should solve your problem.

Sincerely yours,
Petar
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
General Discussions
Asked by
Denis Vulinovich
Top achievements
Rank 1
Answers by
Denis Vulinovich
Top achievements
Rank 1
Jan Blessenohl
Telerik team
Iftekhar Ivaan
Top achievements
Rank 1
IT-Als
Top achievements
Rank 1
PetarP
Telerik team
Zoran
Telerik team
Share this question
or