How do you create a visual model of EntityFramework code first

前端 未结 4 1488
忘掉有多难
忘掉有多难 2020-12-07 09:19

If you look here you will notice that this guy is showing the Entity Model Diagrams, I would like to know how I can create an Entity Model Diagram from my EntityFramework co

4条回答
  •  一个人的身影
    2020-12-07 09:52

    To retain layout from a previous EF Power Tools generated diagram, this will carry over the Entities positions and colours etc. that exist in the new one, and leave any additions as is. Otherwise you don't see the new entities in the diagram.

        static void CopyLayout(string srcFile, string destFile)
        {
            var oldModel = XDocument.Load(srcFile);
            var newModel = XDocument.Load(destFile);
    
            XNamespace edmxNs = "http://schemas.microsoft.com/ado/2009/11/edmx";
            // find all entity shapes
            var oldEts = oldModel.Root.Descendants(edmxNs + "EntityTypeShape").Select(ets => ets).ToList();
            var newEts = newModel.Root.Descendants(edmxNs + "EntityTypeShape").Select(ets => ets).ToList();
            // replace any matching new with old
            foreach (var newEt in newEts)
            {
                var match = oldEts.SingleOrDefault(ot => ot.Attribute(@"EntityType").Value ==
                                                         newEt.Attribute(@"EntityType").Value);
                if (match != null)
                    newEt.ReplaceAttributes(match.Attributes());
            }
            newModel.Save(destFile);
        }
    

提交回复
热议问题