views:

12

answers:

0

I'm using the entity framework

My customer class has an AccountID property that includes account information from other tables (such as address and specific account info) by loading the other tables into the property based on their relationships.

like this:

tblAccount acct = new tblAccount();
tblCust cust;
tblAddress addr;

public Customers()
{
    if (acct.tblCust != null)
        cust = acct.tblCust;
    else
        cust = new tblCust();

    if (cust.tblAddress != null)
        addr = cust.tblAddress;
    else addr = new tblAddress();
}

public int AccountID
{
    get { return acct.AccountID; }
    set 
    {                
        acct.AccountID = value;
        acct = context.tblAccount.Include("tblCust").Include ("tbl.tblCodes_Address").Where(a => a.AccountID == value).First();
        cust = acct.tblCust;
        addr = cust.tblAddress;
    }
}

When I try to do the same in my InvoiceDetails class - to create a property 'DetailID' that will include the invoice information and the customer details - it doesn't work.

It gives me 'Object is not set to an instance of an object' on the Invoice table. The Invoice table is null

It can't seem to load it properly from the Invoice Detail table

The only thing I can think of is that our database was missing a relationship between the Invoice and InvoiceDetail table so I added an association between the two tables in the entity model.

Does this relationship behave differently than a regular relationship????