Last active
April 1, 2024 19:33
-
-
Save ianfnelson/7ec3a22c992425ebe555 to your computer and use it in GitHub Desktop.
Snippets for 2011 blog post "Entity Framework Week Part 2: Conventions and Fluent Mappings"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyAppPrimaryKeyConvention : IConfigurationConvention<PropertyInfo, PrimitivePropertyConfiguration> | |
{ | |
public void Apply(PropertyInfo memberInfo, Func<PrimitivePropertyConfiguration> configuration) | |
{ | |
if (memberInfo.Name == "Id") | |
{ | |
// We need to avoid overriding concrete class mapped using TPH. | |
if (memberInfo.ReflectedType.IsSubclassOf(typeof(ProductFeature)) || | |
memberInfo.ReflectedType.IsSubclassOf(typeof(ProductInsert))) | |
{ | |
return; | |
} | |
configuration().ColumnName = string.Format("{0}Id", memberInfo.ReflectedType.Name); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyAppPrimaryKeyConvention : IIdConvention | |
{ | |
public void Apply(IIdentityInstance instance) | |
{ | |
instance.Column(string.Format("{0}Id", instance.EntityType.Name)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
References(x => x.AudioFormat).Column("AudioFormat"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HasOptional(x => x.AudioFormat) | |
.WithMany() | |
.IsIndependent() | |
.Map(m => m.MapKey(a => a.Id, "AudioFormat")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment