entity framework 5 MaxLength

前端 未结 4 1551
灰色年华
灰色年华 2020-12-28 17:47

I was using EF4 and a piece of code I found to get the MaxLength value from an entity like this:

public static int? GetMaxLength(string entityTy         


        
4条回答
  •  半阙折子戏
    2020-12-28 18:22

    I had similar issue and solution is here;

      MyDBEntities ctx = new MyDBEntities();
            var objectContext = ((IObjectContextAdapter)ctx).ObjectContext;
    
            var cols = from meta in objectContext.MetadataWorkspace.GetItems(DataSpace.CSpace)
                       .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType)
                       from p in (meta as EntityType).Properties
                          .Where(p => p.DeclaringType.Name == "TableName")
                       select new
                       {
                           PropertyName = p.Name                          
                       };
    

提交回复
热议问题