I have the following POCO Classes:
public class Client
{
public string ClientId { get; set; }
public string CompanyId { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
[ForeignKey("AccountId")]
public virtual ICollection<Note> Notes { get; set; }
}
public class Note
{
public decimal NoteId { get; set; }
public string AccountId { get; set; }
public string NoteValue { get; set; }
[ForeignKey("ClientId")]
public virtual Client Client { get; set; }
}
and the following mapping classes:
public ClientMap(string schema)
{
ToTable("CLIENTS", schema);
// Primary Key
HasKey(t => t.ClientId);
// Properties
Property(t => t.ClientId)
.HasColumnName("CLIENT_ID")
.IsRequired()
.HasMaxLength(16);
Property(t => t.CompanyId)
.HasColumnName("COMPANY_ID")
.IsRequired()
.HasMaxLength(16);
Property(t => t.LastName)
.HasColumnName("LAST_NAME")
.IsRequired()
.HasMaxLength(50);
Property(t => t.FirstName)
.HasColumnName("FIRST_NAME")
.IsRequired()
.HasMaxLength(50);
}
public NoteMap(string schema)
{
ToTable("NOTES", schema);
// Primary Key
HasKey(t => t.NoteId);
// Properties
Property(t => t.NoteId)
.HasColumnName("NOTE_ID")
.HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
Property(t => t.AccountId)
.HasColumnName("ACCOUNT_ID")
.IsRequired()
.HasMaxLength(16);
Property(t => t.NoteValue)
.HasColumnName("NOTE")
.HasMaxLength(4000);
}
In this model (Using Fluent API), there is a one to many relationship between clients and notes. ClientID
is the PK in clients and NoteId
is the PK in Notes. There are no foreign keys in the DB. ClientId
maps to the AccountId
in Notes.
I can not get this to work. When I run it, I can get most of the client data back, but when trying to navigate to a note, I get a Funcation Evaluation Timed out error when trying to look at Notes. I can not get the relationship between clients and notes to work. Where have I gone wrong? (I would like to do this using Fluent API)
Thanks