I have a very strange problem when using Entity Framework with Code First approach. I have disabled lazy loading and are using include statements when I need. Unfortunately I cannot show you the code, but will try to explain as detailed I can.
I have two tables where one is referring to the other:
TableA (ID, Name)
TableB (ID, ForeignKeyTableA)
The corresponding classes:
public class A
{
public int ID { get; set; }
public string Name { get; set; }
}
public class B
{
public int ID { get; set; }
public A ClassA { get; set; }
}
I can load A and B by themselves without and problem, but when I write for example: Include(p => p.A) when loading B and finally calling ToList() it will cause an OutOfMemoryException after a while.
The tables aren't that big. Table A have around 600 records and table B 5 records.
The mapping for class A looks like this:
this.ToTable("TableA");
this.HasKey(p => p.ID);
this.Property(p => p.ID).HasColumnName("ID");
this.Property(p => p.ID).HasColumnName("Name");
The mapping for class B looks like this:
this.ToTable("TableB");
this.HasKey(p => p.ID);
this.Property(p => p.ID).HasColumnName("ID");
HasRequired(p => p.A).WithOptional()
.Map(m => m.MapKey("ForeignKeyTableA"));
I need to map them because the column and table names aren't by convention. Include can be used on other objects without any problems.
The weirdest thing is that when I am using Include() the database will never be hit.
Anyone got suggestions? Because I am really running out of ideas now.