문제

I'm trying to write T4 templates to generate custom Views for my model classes, the model classes are located in another Assembly and the mappings are based on EF6 fluent API.

Currently, I'm using reflection to get properties' names and types, my question is how can I read the ModelConfiguration? , for example to get the Primary Key and related models' foreign keys.. etc.

도움이 되었습니까?

해결책

samples access the Model. Note DataSpace has other Enum values

public void EFTools2Test()
    {
        var context = new MyContext("MYConnie");
        ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
        MetadataWorkspace workspace = objContext.MetadataWorkspace;
        IEnumerable<EntityType> managedTypes = workspace.GetItems<EntityType>(DataSpace.OSpace);
        var result = new List<Type>();
        foreach (var managedType in managedTypes) {

            Console.WriteLine(managedType.FullName);
            foreach ( var p in managedType.Properties) {
                Console.WriteLine(p.Name );
            }
        }


    }



    public void EFToolsTest() {
    //  http://msdn.microsoft.com/en-us/library/system.data.metadata.edm.dataspace(v=vs.110).aspx
        var context = new MyContext("MYConnie");
        ObjectContext objContext = ((IObjectContextAdapter)context).ObjectContext;
        MetadataWorkspace workspace = objContext.MetadataWorkspace;

        var xyz = workspace.GetItems<EntityType>(DataSpace.SSpace);
        foreach (var ET in xyz) {
            foreach (var sp in ET.Properties) {
                Debug.WriteLine(sp.Name + ":" + sp.MaxLength);// just as an example

                }
            }
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top