Skip to content

Commit

Permalink
Support mapping to fields
Browse files Browse the repository at this point in the history
Issues #4357, #4855

This change adds fluent and lower-level APIs to set backing fields or properties with no fields as well as conventions for using the fields and a mechanism to provide control over when the property is used and when the field is used.

Also see #6266, #6267, and #6268.
  • Loading branch information
ajcvickers committed Aug 10, 2016
1 parent bac157d commit b0c503d
Show file tree
Hide file tree
Showing 80 changed files with 4,846 additions and 939 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ public class RelationalColumnAttributeConvention : PropertyAttributeConvention<C
/// This API supports the Entity Framework Core infrastructure and is not intended to be used
/// directly from your code. This API may change or be removed in future releases.
/// </summary>
public override InternalPropertyBuilder Apply(InternalPropertyBuilder propertyBuilder, ColumnAttribute attribute, PropertyInfo clrProperty)
public override InternalPropertyBuilder Apply(
InternalPropertyBuilder propertyBuilder, ColumnAttribute attribute, MemberInfo clrMember)
{
if (!string.IsNullOrWhiteSpace(attribute.Name))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.EntityFrameworkCore.Storage;
using Xunit;

Expand Down Expand Up @@ -190,6 +189,29 @@ protected class PrivateMemberAnnotationClass
private string PersonFirstName { get; set; }
}

[Fact]
public virtual ModelBuilder Field_annotations_are_enabled()
{
var modelBuilder = CreateModelBuilder();

modelBuilder.Entity<FieldAnnotationClass>().Property<string>("_personFirstName");

Validate(modelBuilder);

Assert.True(GetProperty<FieldAnnotationClass>(modelBuilder, "_personFirstName").IsPrimaryKey());

return modelBuilder;
}

protected class FieldAnnotationClass
{
#pragma warning disable 169
[Key]
[Column("dsdsd", Order = 1, TypeName = "nvarchar(128)")]
private string _personFirstName;
#pragma warning restore 169
}

[Fact]
public virtual void NotMapped_should_propagate_down_inheritance_hierarchy()
{
Expand Down
Loading

0 comments on commit b0c503d

Please sign in to comment.