fluent mapping issues with IsDependent(), IsManaged()

Thread is closed for posting
2 posts, 0 answers
  1. Jason
    Jason avatar
    3 posts
    Member since:
    Dec 2012

    Posted 07 Jan 2013 Link to this post


    I'm using the fluent API and am struggling to get IsDependent() and isManaged() to work properly. Here is a representative minimal configuration. With this deletes don't cascade, and the container isn't managed. (Note I'm using the latest release as of December).

    This seems identical to the examples in the documentation... what could I be doing wrong?


    public class User
            public User()
                this.QueryViews = new List<QueryView>();
            public int Id { get; set; }
            public string Name { get; set; }
            public IList<QueryView> QueryViews { get; set; }
        public class QueryView
            public int Id { get; set; }
            public string Name { get; set; }
            public int OwnerId { get; set; }
            public User Owner { get; set; }

    MappingConfiguration<User> userConfiguration = new MappingConfiguration<User>();
    userConfiguration.MapType(x => new
        Id = x.Id,
        Name = x.Name,
    userConfiguration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc);
    userConfiguration.HasIndex(u => u.Name).IsUnique().WithName("Users_Name_Unique");
    MappingConfiguration<QueryView> queryViewConfiguration = new MappingConfiguration<QueryView>();
    queryViewConfiguration.MapType(x => new
        Id = x.Id,
        Name = x.Name,
        Owner = x.OwnerId,
    queryViewConfiguration.HasProperty(x => x.Id).IsIdentity(KeyGenerator.Autoinc);
    queryViewConfiguration.HasAssociation(c => c.Owner).WithOpposite(u => u.QueryViews).HasConstraint((q, u) => q.OwnerId == u.Id).IsManaged().IsDependent().IsRequired();

  2. PetarP
    PetarP avatar
    754 posts

    Posted 10 Jan 2013 Link to this post

    Hello Jason,

     The problem here is caused by the mapping itself. The is dependent setting should always be set on the collection side of an association. If set on the one side it will not work.
    If you move your association definition from the queryView configuration to the user configuration everything should work out as expected:

    userConfiguration.HasAssociation(x => x.QueryViews)
                 .WithOpposite(x => x.Owner).HasConstraint((q, u) => q.Id == u.OwnerId).

    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Back to Top