c# - Parse big XML feed and split information into several models -
i have large xml feed student information.
<students> <student> <studentid>10</studentid> <name>joe doe</name> <location>main street</location> <studyid>1001</studyid> <study>business 101</study> </student> <student> <studentid>255</studentid> <name>max friedman</name> <location>main street</location> <studyid>223</studyid> <study>computer science</study> </student> <student> <studentid>452</studentid> <name>josephine smith</name> <location>clinton dr.</location> <studyid>881</studyid> <study>english literature</study> </student> ... (2000 more rows) </students>
i want store information in 3 seperate models, not want parse xml more once.
the models:
public class student { [databasegenerated(databasegeneratedoption.none)] public long studentid { get; set; } // use id feed public string name { get; set; } public long studyid { get; set; } [foreignkey("studyid")] public virtual study study { get; set; } } public class study { [databasegenerated(databasegeneratedoption.none)] public long studyid { get; set; } public string name { get; set; } public virtual icollection<student> students { get; set; } } public class location { public long locationid { get; set; } public string name { get; set; } public virtual icollection<study> studies { get; set; } public virtual icollection<student> students { get; set; } }
i have tried different ways this, everytime ends messy, ugly , totally spaghetticode.
in pseudocode did following:
for each student in xml create new student object check if location object exists in db if not, create location object add location object student object etc... etc... persist icollection of students db
how can accomplish want in least amount of code?
Comments
Post a Comment