I need to grab the field size of a column in a model using Entity Framework 6 (the model was defined in the database and the field size is not known at run-time).
I see some sample code for EF4/5 here:
But unfortunately, this code is broken in EF6:
var test = objectContext.MetadataWorkspace.GetItems(DataSpace.CSpace); if(test == null) return null; var q = test .Where(m => m.BuiltInTypeKind == BuiltInTypeKind.EntityType) .SelectMany(meta => ((EntityType) meta).Properties .Where(p => p.Name == columnName && p.TypeUsage.EdmType.Name == "String"));
Reason for this being that objectContext.MetadataWorkspace.GetItems no longer seems to return the same collection type as before, so you can't just search through the collection set in the same way using the 'where' method etc.
Has anybody any ideas of how to tackle this problem in EF6?
Problem was down to my using/includes. These are required:
using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Data.Entity.Core.Metadata.Edm; using System.Linq.Expressions; using System.Linq; using System;