类型 xx 的成员 xxx 是接口,因此无法将其序列化。

修改.tt模板文件,添加以下标红两行

<#
foreach (var navigationProperty in navigationProperties)
{

#>

[Newtonsoft.Json.JsonIgnore]

[System.Xml.Serialization.XmlIgnore]

<#
if (navigationProperty.ToEndMember.RelationshipMultiplicity == RelationshipMultiplicity.Many)
{
#>
[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

相关文章:

  • 2022-12-23
  • 2022-01-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-12-23
猜你喜欢
  • 2021-05-17
  • 2022-12-23
  • 2021-06-25
  • 2021-10-30
  • 2021-06-10
  • 2022-12-23
相关资源
相似解决方案