/// <summary> /// Sets an annotation in the model for the table to which this entity is mapped. The annotation /// value can later be used when processing the table such as when creating migrations. /// </summary> /// <remarks> /// It will likely be necessary to register a <see cref="IMetadataAnnotationSerializer"/> if the type of /// the annotation value is anything other than a string. Calling this method will have no effect if the /// annotation with the given name has already been configured. /// </remarks> /// <param name="name">The annotation name, which must be a valid C#/EDM identifier.</param> /// <param name="value">The annotation value, which may be a string or some other type that /// can be serialized with an <see cref="IMetadataAnnotationSerializer"/></param>. /// <returns>The same configuration instance so that multiple calls can be chained.</returns> public ConventionTypeConfiguration <T> HasAnnotation(string name, object value) { Check.NotEmpty(name, "name"); _configuration.HasAnnotation(name, value); return(this); }
public void HasAnnotation_evaluates_preconditions() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("name"), Assert.Throws <ArgumentException>(() => config.HasAnnotation(null, null)).Message); Assert.Equal( Strings.ArgumentIsNullOrWhitespace("name"), Assert.Throws <ArgumentException>(() => config.HasAnnotation(" ", null)).Message); Assert.Equal( Strings.BadAnnotationName("Cheese:Pickle"), Assert.Throws <ArgumentException>(() => config.HasAnnotation("Cheese:Pickle", null)).Message); }
public void HasAnnotation_configures_only_annotations_that_have_not_already_been_set() { var type = new MockType(); var innerConfig = new EntityTypeConfiguration(type); innerConfig.SetAnnotation("A1", "V1"); var config = new ConventionTypeConfiguration(type, () => innerConfig, new ModelConfiguration()); var result = config.HasAnnotation("A1", "V1B").HasAnnotation("A2", "V2"); Assert.Equal("V1", innerConfig.Annotations["A1"]); Assert.Equal("V2", innerConfig.Annotations["A2"]); Assert.Same(config, result); }