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

fluent mapping issues with IsDependent(), IsManaged()

1 Answer 72 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.
Jason
Top achievements
Rank 1
Jason asked on 07 Jan 2013, 04:56 PM
Hi,

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?

Thanks,
Jason

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,
}).ToTable("Users");
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,
}).ToTable("QueryViews");
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();

1 Answer, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 10 Jan 2013, 04:25 PM
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).
             .IsManaged()
             .IsDependent()
             .IsRequired();

Greetings,
Petar
the Telerik team
Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Tags
Getting Started
Asked by
Jason
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Share this question
or