On the issue of Jsonignore,
The primary foreign key relationship exists in the EF T4 template
Namespace WindowsFormsApplication1
{
Using System;
Using System.Collections.Generic;
Using Newtonsoft.json;
public partial class Materielprocedures
{
public int Kid {get; set;}
Public nullable<int> Okid {get; set;}
public int Node {get; set;}
public string Proceduretype {get; set;}
public string Procedureneed {get; set;}
public string Author {get; set;}
Public System.DateTime createtime {get; set;}
Public nullable<system.datetime> StartTime {get; set;}
Public nullable<double> Planhour {get; set;}
Public nullable<system.datetime> EndTime {get; set;}
Public nullable<int> PercentAge {get; set;}
public string Procedurestate {get; set;}
public bool Isout {get; set;}
[Jsonignore]
Public virtual bom_2d bom_2d {get; set;}
}
}
BOM_2D is the foreign key of Materielprocedures, use Json.NET to turn Materielprocedures class into JSON string, because this foreign key error.
The workaround is in public virtual bom_2d bom_2d {get; set;} The line above adds [Jsonignore].
However, each time the template is regenerated, the Materielprocedures class is regenerated.
So directly to find the source of the problem, to modify, tracking N multi-Method finally
Private voidSerializeObject (Jsonwriter writer,Objectvalue, jsonobjectcontract contract, Jsonproperty member, Jsoncontainercontract collectioncontract, JsonProperty Containerproperty) {onserializing (writer, contract, value); _serializestack.add (value); Writeobjectstart (writer, value, contract, member, Collectioncontract, Containerproperty); intInitialdepth =writer. Top; for(intindex =0; Index < contract. Properties.Count; index++) {Jsonproperty property=contract. Properties[index]; Try { ObjectMembervalue; Jsoncontract membercontract; if(! Calculatepropertyvalues (writer, value, contract, Member, property, outMembercontract, outmembervalue)) Continue; #regionAdd by 253if(!membercontract.createdtype.basetype.fullname.contains ("System.")) Continue; #endregionProperty . Writepropertyname (writer); Serializevalue (writer, membervalue, Membercontract, property, contract, member); } Catch(Exception ex) {if(iserrorhandled (value, contract, property.) PropertyName,NULL, writer. Containerpath, ex)) HandleError (writer, initialdepth); Else Throw; } } if(Contract. Extensiondatagetter! =NULL) {IEnumerable<KeyValuePair<Object,Object>> ExtensionData =contract. Extensiondatagetter (value); if(ExtensionData! =NULL) { foreach(keyvaluepair<Object,Object> EinchExtensionData) {jsoncontract Keycontract=Getcontractsafe (E.key); Jsoncontract valuecontract=Getcontractsafe (E.value); BOOLescape; stringPropertyName = Getpropertyname (writer, E.key, Keycontract, outescape); if(Shouldwritereference (E.value,NULL, Valuecontract, contract, member)) {writer. Writepropertyname (PropertyName); Writereference (writer, e.value); } Else { if(! Checkforcircularreference (writer, E.value,NULL, Valuecontract, contract, member)) Continue; Writer. Writepropertyname (PropertyName); Serializevalue (writer, e.value, Valuecontract,NULL, contract, member); }}}} writer. Writeendobject (); _serializestack.removeat (_serializestack.count-1); OnSerialized (writer, contract, value); }
It's done! Except for the data type under System, all continue!