Q: How can I separate this Entity Framework model to prevent memory errors? I am trying to work with a set of data from a legacy app and move it into a MSSQL database.  I created an app in C# with EF to manage the data.  The class structure as it is represents old C style arrays from the legacy app but with some class order.
These are the three main classes.  Other properties are involved but I have included only the main form and memory hog (AccountDetails) here.  When this structure is built out it has One Simulation - from 50 to 100 accounts and then each account has between 1000 or more Account detail objects.
If I add the whole structure at once - and do save changes I get a Memory error.  How can I add all my AccountDetail objects and keep it linked as one object structure?  Can I add them separately (I have all ID's and one to Many's setup properly though not all details are included here).
public class Simulation 
{
    public string Name { get; set; }
    public List<Account>     Accounts { get; set; }
}

public class Account
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Type { get; set; }
    public List<AccountDetail>     Details { get; set; }
}
// trouble in here....
public class AccountDetail
{
    public int Id { get; set; }
    public int Type { get; set; }
    public int Scenario { get; set; }
    public double M01 { get; set; }
     ..... class has 60 doubles for 5 years of payments ....
    public double M60 { get; set; }
} 

Thanks,
K.

A: Well, since you have all ids. Just do the following.


*

*Create Simulation object and populate it only with non-navigation properties (so ints, doubles etc.) Save changes.

*Create a list of Accounts and populate it only with non-navigation properties, but make sure that SimulationID (or the foreign key you are using to link Account to simulation is filled in). Save changes.

*Create  list of AccountDetails, populate it only with non-navigation properites, but make sure that AccountID (or the foreign key you are using to link Account details to Account is filled in).
In entity framework, you don't need all the objects to be in memory. It's the foreign keys that matter. Now you can save the memory by saving only 10 accounts at a time if you want to. But to be honest, I haven't seen yet EF complaining about memory, so that raises question... have you set up everything correctly?
