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

How to set constraint name in fluent modeling

1 Answer 45 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Eugeniy
Top achievements
Rank 2
Eugeniy asked on 03 Nov 2015, 07:36 AM

Hello.
Is it possible to set the exact constraint name?

My code:

 

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

1 Answer, 1 is accepted

Sort by
0
Accepted
Ady
Telerik team
answered on 06 Nov 2015, 10:46 AM
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.


Regards,
Ady
Telerik
 
Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Tags
Development (API, general questions)
Asked by
Eugeniy
Top achievements
Rank 2
Answers by
Ady
Telerik team
Share this question
or