How to set constraint name in fluent modeling

2 posts, 1 answers
  1. Eugeniy
    Eugeniy avatar
    60 posts
    Member since:
    Feb 2011

    Posted 03 Nov 2015 Link to this post

    Is it possible to set the exact constraint name?

    My code:


    configuration.HasAssociation(job => job.TriggerAgent)
                        .WithOpposite(agent => agent.AK_RecognitionJobs)
                        .HasConstraint((job, agent) => job.TriggerAgentId == agent.Id);

  2. Answer
    Ady avatar
    588 posts

    Posted 06 Nov 2015 Link to this post

    Hi Eugeniy,

     Unfortunately there is no method to specify the constraint name explicitly. Nevertheless you can create a partial class for the context and override the OnDatabaseOpen method and add code like the following

    1.protected override void OnDatabaseOpen(Telerik.OpenAccess.BackendConfiguration backendConfiguration, Telerik.OpenAccess.Metadata.MetadataContainer currentMetadataContainer, Telerik.OpenAccess.Metadata.MetadataContainer aggregatedMetadataContainer)
    2.        {
    3.            var fkAssociations = currentMetadataContainer.Associations.OfType<MetaForeignKeyAssociation>().ToList();
    4.            var constraint = fkAssociations.Where(a => a.SourceEnd.PropertyName.Equals("TriggerAgent")).Single().Constraint;
    5.            constraint.Name = "YourConstraintName";
    6.        }

     Hope this helps and do get back in case you need further assistance.

    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  3. DevCraft banner
Back to Top