Skip to content

Instantly share code, notes, and snippets.

@sitereactor
Created June 9, 2013 08:23
Show Gist options
  • Save sitereactor/5742799 to your computer and use it in GitHub Desktop.
Save sitereactor/5742799 to your computer and use it in GitHub Desktop.
Example of a POCO that is used internally in Umbraco and decorated with various attributes to enable the creation of a table, columns, keys, constraints and indexes using .CreateTable().
using System;
using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.DatabaseAnnotations;
namespace Umbraco.Core.Models.Rdbms
{
[TableName("umbracoNode")]
[PrimaryKey("id")]
[ExplicitColumns]
internal class NodeDto
{
[Column("id")]
[PrimaryKeyColumn(Name = "PK_structure", IdentitySeed = 1045)]
public int NodeId { get; set; }
[Column("trashed")]
[Constraint(Default = "0")]
public bool Trashed { get; set; }
[Column("parentID")]
[ForeignKey(typeof(NodeDto))]
[IndexAttribute(IndexTypes.NonClustered, Name = "IX_umbracoNodeParentId")]
public int ParentId { get; set; }
[Column("nodeUser")]
[NullSetting(NullSetting = NullSettings.Null)]
public int? UserId { get; set; }
[Column("level")]
public short Level { get; set; }
[Column("path")]
[Length(150)]
public string Path { get; set; }
[Column("sortOrder")]
public int SortOrder { get; set; }
[Column("uniqueID")]
[NullSetting(NullSetting = NullSettings.Null)]
public Guid? UniqueId { get; set; }
[Column("text")]
[NullSetting(NullSetting = NullSettings.Null)]
public string Text { get; set; }
[Column("nodeObjectType")]
[NullSetting(NullSetting = NullSettings.Null)]
[IndexAttribute(IndexTypes.NonClustered, Name = "IX_umbracoNodeObjectType")]
public Guid? NodeObjectType { get; set; }
[Column("createDate")]
[Constraint(Default = "getdate()")]
public DateTime CreateDate { get; set; }
}
}
@jaredchu
Copy link

Please provide an example that changes string data to "text" type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment