Some advice about EF/designe software performance RRS feed

  • Question

  • Hi all,

    to be honest my problem is more about the design software. EF is working fine for now... However my scenario is:

    I have 2 tables (let say a 'DFC' table and a 'FID' table, everyone with its attributes). There are others 2 tables:

    - a 'Project table' rappresents the number (and name) of the projects my software handles (Note: the number of projects is dynamic);

    - an 'Association' table where every table maps a relation between  one record in my DFC table  to a record in FID table. Every association has an attribute indicates the type (LIM attribute) of associations and the project where is working. Example:

    What I need to do?

    Show in my clients a table to rappresent (for every DFC/FID) the associations with the type (LIM) for every projects AND if the association is missing tells why. More in detail if the association is simply missing or can't be present for that pair DFC/FID (for example because a DFC is missing for a specific project). Something like that:

    My problem is about performance. I get what I need using EF. Example:

    dfcList = (from d in context.Dfcs.Include("associations") where d.SoftwareVersion == projectId orderby d.Label select d).ToList<Dfc>();
    fidList = (from f in context.Fids.Include("associations") where f.SoftwareVersion == projectId orderby f.Label select f).ToList<Fid>();
    limList = (from l in context.Lims where l.SoftwareVersion == projectId select l).ToList<Lim>();

    That's ok. But since I need to parse these lists my code becomes very slow. Here:

    if (dfcList!= null && fidList != null && limList != null)
                    JArray jaDfcs = new JArray();
                    JArray jaFids = new JArray();
                    JArray jaLims = new JArray();
                    foreach (Dfc dfc in dfcList)
                        JObject joDfc = new JObject();
                        JArray jaAss = new JArray();
                        joDfc.Add("label", dfc.Label);
                        joDfc.Add("description", dfc.Description);
                        joDfc.Add("currentSize", dfc.CurrentSize);
                        joDfc.Add("totSize", dfc.SizeTot);
                        joDfc.Add("softwareVersion", dfc.SoftwareVersion);
                        foreach(Association ass in dfc.associations)
                            JObject joFid = new JObject();
                            joFid.Add("label", ass.FID_Label);
                            joFid.Add("lim", ass.LIM_Label);
                            joFid.Add("comment", ass.Comment);
                            Dictionary<short, Boolean> dictionary = dataManagement.getProjectDictionary(ass.FID_Label, dfc.Label); //informazioni sull'associazione su tt i progetti
                            foreach (short projectId in dictionary.Keys)
                                if (dictionary[projectId] == true)
                                    if (projectId == ass.SoftwareVersion)                //sono sul progetto corrente;
                                        joFid.Add(projectId.ToString(), ass.LIM_Label);
                                        joFid.Add(projectId.ToString(), "");
                                    joFid.Add(projectId.ToString().ToString(), "-");
                        joDfc.Add("fid", jaAss);

    What I'm trying to do is parsing my objects I get from DB to create a JSON to populate the table I mentioned before. But I'm obviously slow (about 60-70 for about 5000 records). So: what are some solutions to improve the time of response?  


    - create a simple (or temporany) table with those attributes so I don't need to parse the result?

    - handle just a DFC/FID at time? the number of records decrease. But I need to ask to the server for every label a user selects.

    Some advide? 

    • Edited by Mond089 Monday, November 21, 2016 7:10 AM Insert some images
    Friday, November 18, 2016 7:42 AM

All replies

  • Hi Mond089,

    According to your description, it seems that a huge number of records cause the issue, I would suggest you could reduce the query records per times by using take and skip. For more information, please refer to:

    In addition, Based on your code snippet, it seems that you want to convert list array to JSON object. you could also use the following method if you use Newtonsoft.Json.

    string result = JsonConvert.SerializeObject(dfcList);

    Best regards,

    Cole Wu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, November 22, 2016 9:32 AM