problem with artificial association

3 posts, 1 answers
  1. MATEUSZ
    MATEUSZ avatar
    18 posts
    Member since:
    Jul 2011

    Posted 19 Sep 2013 Link to this post

    Hello, I have a problem with using artificial association.

    Unfortunatelly, I use Telerik-OpenAccess-ORM-2012.2.924.1, but I hope it's not the main problem...

    Some code at first:


    public class Role : EntityBase, IEntityWithKey<int>, INameable
    {
        public int Id { get; set; }
        public string Name { get; set; }
     
        private TrackedBindingList<RoleItem> roleItems = new TrackedBindingList<RoleItem>();
        public IList<RoleItem> RoleItems
        {
            get { return roleItems; }
        }
    }
    public class Fake : EntityBase, IEntityWithKey<int>, INameable
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
     
    var roleMapping = new MappingConfiguration<Role>();
    roleMapping.MapType(u => new
    {
        u.Id,
        u.Name,
    }).ToTable("Roles");
    roleMapping.HasProperty(u => u.Id).IsIdentity(KeyGenerator.Autoinc);
     
    var fakeMapping = new MappingConfiguration<Fake>();
    fakeMapping.MapType(u => new
    {
        u.Id,
        u.Name
    }).ToTable("Fakes");
    fakeMapping.HasProperty(u => u.Id).IsIdentity(KeyGenerator.Autoinc);
    fakeMapping.HasArtificialCollectionAssociation("Roles", typeof(Role))
        .WithOpposite("Fake");
    roleMapping.HasArtificialAssociation("Fake", typeof(Fake))
        .WithOppositeCollection("Roles")
        .ToColumn("FakeId");

    So, I have two classes called Role and Fake. They are mapped and extended with some artificial association. The main purpose of that is to be able to assign instance of Fake to and instance of Role. And here the problem starts:

    var role = new Role();
    var fake = new Fake();
    ctx.Add(role);
    ctx.Add(fake);
    role.SetFieldValue("Fake", fake);

    Unfortunately, this piece of code causes ArgumentOutOfRangeException:
    No such persistent field known.
    Parameter name: nameOfPersistentField
    Actual value was Fake.
    which comes from Telerik.OpenAccess.ExtensionMethods.GetPropertyDescriptor(Object persistentInstance, String nameOfPersistentField)

    Can you see any flaw in my code? Or mayby this is a known issue?

    Thanks...
  2. Answer
    Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 24 Sep 2013 Link to this post

    Hi Mateusz,

    This issue is not reproducible with the latest Telerik OpenAccess ORM official release. I would recommend you to upgrade to the latest release and verify if the problem is still reproducible - in general we do not recommend using custom builds like that once an official version has become available. 

    Kindly let us know if you experience any issues with the new release.

    Regards,
    Boris Georgiev
    Telerik
    OpenAccess ORM Q3 2013 Beta is available for immediate download in your account. Get it now and play with the latest bits. See what's new >>
  3. DevCraft banner
  4. MATEUSZ
    MATEUSZ avatar
    18 posts
    Member since:
    Jul 2011

    Posted 25 Sep 2013 Link to this post

    Latest version works fine, thanks.

    It's great that you made full version of OA free :)
Back to Top