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

Collections not stored

10 Answers 114 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Roman
Top achievements
Rank 1
Roman asked on 24 Sep 2009, 07:30 AM
Heya

My application's ORM won't store collections. E.g. if I have a class with "name", "date" and "children" (the latter is one-to-many) and I define the data the telerik ORM stores name and date, but not the children. It never stores collections (And there's no error). And the collection really contains data, I checked it several times. What am I doing wrong?

Please tell me if a code example is needed.

Thanks in advance for your help
Best
Roman

EDIT:
Here's an example
        public void GeneratePartner(IList<Guid> contacts, String name) 
        { 
            int ScopeID = ScopeFactory.CreateScope(); 
            ScopeFactory.StartTransaction(ScopeID); 
            PartnerFacade partnerfacade = new PartnerFacade(); 
            partnerfacade.ScopeID = ScopeID; 
            Partner partner = new Partner(); 
            partner.partnerID = Guid.NewGuid(); 
            partner.Name = name; 
 
            //contacts 
            ContactFacade contactfacade = new ContactFacade(); 
            List<Contact> contactlist = new List<Contact>(); 
            foreach (Guid contactID in contacts) 
            { 
                Contact contact = contactfacade.Load(contactID, ScopeID); 
                contactlist.Add(contact); 
            } 
            //delete  
            partner.Contacts.Clear(); 
            //store list 
            foreach (Contact finalcontact in contactlist) 
            { 
                partner.Contacts.Add(finalcontact); 
            } 
 
            //store 
            Add(partner, true); 
        } 
 
        public void Add(Object persistenceCapableObject, bool isIsolated) 
        { 
            ScopeFactory.StartTransaction(this.ScopeID); 
 
            try 
            { 
                ScopeFactory.GetScope(this.ScopeID).Add(persistenceCapableObject); 
                if (isIsolated) { ScopeFactory.CommitTransaction(this.ScopeID); } 
            } 
            catch (Exception ex) 
            { 
                ExceptionPolicy.HandleException(ex, "XIS Exception Policy"); 
 
                if (isIsolated) { ScopeFactory.RollbackTransaction(this.ScopeID); } 
                this.Error = ex.Message; 
            } 
            finally 
            { 
                if (isIsolated) { ScopeFactory.DeleteScope(this.ScopeID); } 
            } 
        } 

10 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 26 Sep 2009, 03:26 PM
Hi Roman,

Normally your code should work properly. Is the entry inserted with only the collection missing or is the whole entry not inserted at all? Are you using forward or reverse mapping? Is there a JOIN table between the 'Partner' and 'Contact' tables in the database. Maybe there is some problem in the way your model is specified? Can you please share some more information on your model as that will allow us to get to the problem. We are looking forward to your replay.

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
Roman
Top achievements
Rank 1
answered on 06 Oct 2009, 09:24 AM
Hello Petar

Sorry for the late answer, I was in holidays last week.
Just the collections are missing. The rest is stored (e.g. Strings, ints, bools...). I use reverse mapping.
Partner<-->Contact is a one-to-many relation. Please have a look at this image which displays the tables and its relations.
Since all collections I tested are affected I'd doubt (imho) the problem is located in a specific model. Still, the Contact and the Partner models can be found at the bottom of this post.
As mentioned, the partner.contact collection really contains values (at least it does just before Add(partner, true); is exectued).

Please do not hesitate to require more information or code.
Thanks for your help

Regards,
Roman

 
 
using System; 
using System.Collections.Generic; 
 
namespace XSite.XIS.DataModel  
    // Generated by Telerik OpenAccess 
    // Used template: c:\program files\telerik\openaccess orm\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\default.vm 
    [Telerik.OpenAccess.Persistent(IdentityField="partnerID")] 
    public class Partner  
    { 
        private Guid partnerID; // pk  
 
        private string mainaddress; 
 
        private string name; 
 
        private Partnertype partnertype; // inverse Partnertype.partners 
 
        private State state2; 
 
        private IList<Domain> domains = new List<Domain>();  // inverse Domain.partner 
 
        private IList<Domain> domains2 = new List<Domain>();  // inverse Domain.partner2 
 
        private IList<Key> keys = new List<Key>();  // inverse Key.partner 
 
        private IList<Pc> pcs = new List<Pc>();  // inverse Pc.partner 
 
        private IList<Project> projects = new List<Project>();  // inverse Project.partner 
 
        private IList<Server> servers = new List<Server>();  // inverse Server.partner 
 
        private IList<Contact> contacts = new List<Contact>();  // inverse Contact.partnerContact 
 
        private IList<Password> partnerPasswords = new List<Password>();  // inverse Password.partners 
 
 
        public Partner()  
        { 
        } 
     
        [Telerik.OpenAccess.FieldAlias("partnerID")] 
        public Guid PartnerID 
        { 
            get { return partnerID; } 
            set { this.partnerID = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("mainaddress")] 
        public string Mainaddress 
        { 
            get { return mainaddress; } 
            set { this.mainaddress = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("name")] 
        public string Name 
        { 
            get { return name; } 
            set { this.name = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("partnertype")] 
        public Partnertype Partnertype 
        { 
            get { return partnertype; } 
            set { this.partnertype = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("state2")] 
        public State State2 
        { 
            get { return state2; } 
            set { this.state2 = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("domains")] 
        public IList<Domain> Domains 
        { 
            get { return domains; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("domains2")] 
        public IList<Domain> Domains2s 
        { 
            get { return domains2; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("keys")] 
        public IList<Key> Keys 
        { 
            get { return keys; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("pcs")] 
        public IList<Pc> Pcs 
        { 
            get { return pcs; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("projects")] 
        public IList<Project> Projects 
        { 
            get { return projects; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("servers")] 
        public IList<Server> Servers 
        { 
            get { return servers; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("contacts")] 
        public IList<Contact> Contacts 
        { 
            get { return contacts; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("partnerPasswords")] 
        public IList<Password> PartnerPasswords 
        { 
            get { return partnerPasswords; } 
        } 
  
 
 
    } 
 

using System; 
using System.Collections.Generic; 
 
namespace XSite.XIS.DataModel  
    // Generated by Telerik OpenAccess 
    // Used template: c:\program files\telerik\openaccess orm\sdk\IDEIntegrations\templates\PCClassGeneration\cs\templates\classgen\class\default.vm 
    [Telerik.OpenAccess.Persistent(IdentityField="contactID")] 
    public class Contact  
    { 
        private Guid contactID; // pk  
 
        private string address; 
 
        private string address2; 
 
        private DateTime? birthday; 
 
        private string cfunction; 
 
        private string city; 
 
        private string country; 
 
        private string department; 
 
        private string email; 
 
        private string fax; 
 
        private string name; 
 
        private string plzZip; 
 
        private string prename; 
 
        private string tel; 
 
        private Contacttype contacttype; 
 
        private State state2; 
 
        private IList<ProjectContact> projectContacts = new List<ProjectContact>();  // inverse ProjectContact.contact 
 
        private IList<Partner> partnerContact = new List<Partner>();  // inverse Partner.contacts 
 
 
        public Contact()  
        { 
        } 
     
        [Telerik.OpenAccess.FieldAlias("contactID")] 
        public Guid ContactID 
        { 
            get { return contactID; } 
            set { this.contactID = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("address")] 
        public string Address 
        { 
            get { return address; } 
            set { this.address = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("address2")] 
        public string Address2 
        { 
            get { return address2; } 
            set { this.address2 = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("birthday")] 
        public DateTime? Birthday 
        { 
            get { return birthday; } 
            set { this.birthday = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("cfunction")] 
        public string Cfunction 
        { 
            get { return cfunction; } 
            set { this.cfunction = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("city")] 
        public string City 
        { 
            get { return city; } 
            set { this.city = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("country")] 
        public string Country 
        { 
            get { return country; } 
            set { this.country = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("department")] 
        public string Department 
        { 
            get { return department; } 
            set { this.department = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("email")] 
        public string Email 
        { 
            get { return email; } 
            set { this.email = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("fax")] 
        public string Fax 
        { 
            get { return fax; } 
            set { this.fax = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("name")] 
        public string Name 
        { 
            get { return name; } 
            set { this.name = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("plzZip")] 
        public string PlzZip 
        { 
            get { return plzZip; } 
            set { this.plzZip = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("prename")] 
        public string Prename 
        { 
            get { return prename; } 
            set { this.prename = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("tel")] 
        public string Tel 
        { 
            get { return tel; } 
            set { this.tel = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("contacttype")] 
        public Contacttype Contacttype 
        { 
            get { return contacttype; } 
            set { this.contacttype = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("state2")] 
        public State State2 
        { 
            get { return state2; } 
            set { this.state2 = value; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("projectContacts")] 
        public IList<ProjectContact> ProjectContacts 
        { 
            get { return projectContacts; } 
        } 
  
        [Telerik.OpenAccess.FieldAlias("partnerContact")] 
        public IList<Partner> PartnerContacts 
        { 
            get { return partnerContact; } 
        } 
  
 
 
    } 

0
Roman
Top achievements
Rank 1
answered on 09 Oct 2009, 06:47 AM
Hi

I just wanted to add some visual information of the situation I described.
This is the add method, with the Partner as an object and the two Contacts as a collection: The object
And here you see the database having no entry in PartnerContacts, while it should have two: No entry

Thanks in advance for your help
Kind regards
Roman
0
Roman
Top achievements
Rank 1
answered on 09 Oct 2009, 06:48 AM
Hi

I just wanted to add some visual information of the situation I described.
This is the add method, with the Partner as an object and the two Contacts as a collection: The object
And here you see the database having no entry in PartnerContacts, while it should have two: No entry

Thanks in advance for your help
Kind regards
Roman

PS: I use version 2009.1.405.1
0
Accepted
IT-Als
Top achievements
Rank 1
answered on 09 Oct 2009, 08:15 AM
Hi Roman (and Peter, sorry for interferring in your thread)

I think there's an issue regarding the relationship here... In essence it is a m:n since on Partner you have a list of Contact and on Contact you have a list of Partner.

I guess this relationship is Unmanaged (see the mapping dialog for the relationship - No tick in the Managed collection checkbox) meaning one has to maintain the references on both sides. If you make this relationship Managed everything should be ok.

Regards

Henrik

0
IT-Als
Top achievements
Rank 1
answered on 09 Oct 2009, 08:30 AM
Hi again,

Check these pages in the docs:

Specific in the "Managed many-to-many" section

This is global settings (configuration)
http://www.telerik.com/help/openaccess-orm/configuration-file-format.html

This is per class settings (mappings)
http://www.telerik.com/help/openaccess-orm/map-collection-fields-many-many.html

Regards

HG



0
PetarP
Telerik team
answered on 09 Oct 2009, 09:19 AM
Hi Roman,

It seems that you are indeed having an m:n relationship. You stated that you want 1:n, is that correct? If so you should have List of contact objects in your partner object and only a single reference (but not a List) to partner in your contact object. This way you can achieve 1:n without a join table. This is done because the managed collection is only valid for 1:n relationships that are not using a join table (m:n is only achieved via join table and the managed collection option is active for it).
Please clarify what approach you would like to use. If it is 1:n, please do the changes I suggested. If it is m:n, then please do what hgsdc suggested.
If you are still facing this behavior, would it be possible for you to send us a sample project that reproduces the problem, so we can determine it faster?
We are looking forward to your reply.

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
Roman
Top achievements
Rank 1
answered on 09 Oct 2009, 12:13 PM
Hi

First of all thanks for your answers.
I'll be able to consider your proposals and alike by next tuesday :)
I'll reply here asap.

Thanks, best
Roman
0
Roman
Top achievements
Rank 1
answered on 15 Oct 2009, 12:55 PM
Hello hgsdc & Petar

Thanks a lot for your responses.
Indeed I had to check the option "managed" for relations in the Backend Configuration Settings in order to make it work.

So many thanks for your patience & support :)
Best
Roman
0
IT-Als
Top achievements
Rank 1
answered on 15 Oct 2009, 01:24 PM
Hi Roman,

Glad I (we) could help :-)

Be aware though that since you change this in the Backend Configuration Settings it default to use managed many-to-many for all relationships you have of this type.

Regards

HG
Tags
Getting Started
Asked by
Roman
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Roman
Top achievements
Rank 1
IT-Als
Top achievements
Rank 1
Share this question
or