Skip to content
Mike Mogosanu edited this page Apr 19, 2016 · 8 revisions

Keeping The POCOs Clean (v2 only)

  • create the POCO
  • create a 'buddy' class which will hold the SqlFu attributes
  • decorate the POCO with [MetadataType(typeof(BuddyClass))]
  • or create the POCO as partial classes and one of them will be decorated with [MetadataType]
 public partial class User
    {
    
        public int Id { get; set; }
        
        public string Name { get; set; }
        
        public DateTime RegisteredAt { get; set; }
        
        public Guid? UserId { get; set; }
      
        public IfTableExists Options { get; set; }
      
        public string Bla { get; set; }

        public byte[] Data { get; set; }
      
        public string OK { get; set; }
    }

    [Table("Users")]
    [Index("Email", Name = "ix_email")]
    [PrimaryKey("Id", AutoIncrement = true, Name = "PK_Users")]
    public class UserMetaData
    {
        [ForeignKey("ParentT", "ParentC", OnDelete = ForeignKeyRelationCascade.Cascade)]
        public string Name { get; set; }

        [RedefineFor(DbEngine.SqlServer, "bla")]
        [ColumnOptions(DefaultValue = "test", Size = "50")]
        public string Bla { get; set; }

        [ColumnOptions(IsNullable = true)]
        public string OK { get; set; }
    }


    [MetadataType(typeof(UserMetaData))]
    public partial class User
    {
        
    }