public static int? GetMaxLength(this System.Data.Entity.DbContext context, string tableName, string propertyName)
{
var oc = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)context).ObjectContext;
return oc.MetadataWorkspace.GetItems(System.Data.Entity.Core.Metadata.Edm.DataSpace.CSpace).OfType<System.Data.Entity.Core.Metadata.Edm.EntityType>()
.Where(et => et.Name == tableName)
.SelectMany(et => et.Properties.Where(p => p.Name == propertyName))
.Select(p => p.MaxLength)
.FirstOrDefault();
}
沒有留言:
張貼留言