-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Possible feature request like in DLinq
PostPosted: Mon Sep 15, 2008 5:22 am 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
in Dlinq there is really neat feature
something similar like mapping a "many-to-one" but thre can be used extra property for reference ID
// Example
So I have 2 classes
Code:
public class A
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }

   public class B
    {       
        public int Id { get; set; }
        public string Name { get; set; }
        public A MappedA { get; set; } //this is many-to-one mapping
        public int AId { get; set; }   //this should be a id for inserted a
    }


So I created little unit test for this

Code:
public void MapManyToOneAndPropertyUsesSameColumnFixture()
        {
            ISession s = OpenSession();

            A a = new A {Name = "First"};
            s.Save(a);
           


            B b = new B {Name = "Second", AId = a.Id};
            s.Save(b);
            s.Flush();//This throws an System.IndexOutOfRangeException: Invalid index 3 for this SqlParameterCollection with Count=3.
            s.Close();

            s = OpenSession();
            B newB = s.Get<B>(b.Id);
            Assert.IsNull(b.MappedA);
            s.Close();

        }   
      


So I think it would be nice to have this feature, althoug there is another way but I like the DLinq approach for this case.
Code:
            A a = new A {Name = "First"};
            s.Save(a);
           


            B b = new B {Name = "Second", MappedA = session.Get<A>(a.Id)};
            s.Save(b);
     


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 21, 2008 1:01 pm 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
Another option why this would be an useful.

For instance There is combobox filled with query "select a.Id, a.Name from A a" so actually this is a array of results, not an instance of A.

And I bind this B class by MappedA property, then to update this value I must reload A- instance from session and then persist updates.

But when I could either update property AId by int value, this would not cause that much database traffic.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.