Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,

I am working with EF 6, generated entity data model from mysql db. So i have some partial classes. The problem is that when i create a new object that have a navigation property, initially this navigation property is null. So there is my simle code:

C#
public partial class Person
{
    public Person()
    {
        ....
    }

    ....

    public Nullable<int> phoneID{ get; set; }
    public virtual Phones phones{ get; set; }

}

.....


public partial class Person
{
    public string PhoneName { return this.phones.phonename; }

    //SO ERROR APPEARS HERE. this.phones is NULL
}
Posted
Updated 9-Apr-15 3:21am
v3
Comments
Sergey Alexandrovich Kryukov 9-Apr-15 11:54am    
It has nothing to do with partial. During runtime, partial class is no different from non-partial. You got null, so what?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900