POCO template
来自微软。效果很好。
我尝试的方法是使用模板创建POCO,然后pogenerator上下文使用现有模型,然后修改生成的代码以返回我的类而不是其生成的类。
有人这么做过吗?
乳房
无论如何,要使用现有的类作为poco,只需生成poco,然后将生成的类注释掉。比在xxxPocoGenerator.Context.cs添加要使用的现有对象的必需命名空间。
作为补充说明,我编写了以下代码来比较我现有的类和POCO生成的类,并显示任何不匹配的类,以便我可以修复它们。
var properties = typeof(MyExistingClass).GetProperties();
var tproperties = typeof(MyPOCOClass).GetProperties();
Console.WriteLine("---------------------------------Missing or Different Properties--------------------");
List<PropertyInfo> missingOrDifferentProperties = new List<PropertyInfo>();
foreach (var tp in tproperties)
if (properties.Where(p => p.Name == tp.Name && p.PropertyType == tp.PropertyType && p.CanRead == tp.CanRead && p.CanWrite == tp.CanWrite && p.IsSpecialName == tp.IsSpecialName && p.MemberType == tp.MemberType).Count() != 1)
Console.WriteLine(tp.Name + " :: " + tp.PropertyType.Name);