修改.tt模板文件,添加以下标红两行
<#
foreach (var navigationProperty in navigationProperties)
{
if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
#>
[Newtonsoft.Json.JsonIgnore]
[System.Xml.Serialization.XmlIgnore]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
<#
使用
DBEntities dc = new DBEntities();
dc.Configuration.ProxyCreationEnabled = false;
var list=dc.News.ToList();
return list; //此时list可成功序列化
From:http://www.cnblogs.com/xuejianxiyang/p/6794928.html
时间: 2024-10-13 23:44:46