C# .NET - to access other class entity property in parent class
Asked By anbu n on 17-Mar-12 01:18 AM
namespace DPR_Web.Entities
{
public class Master_general
{
public int Master_Static_Id { get; set; }
public string Static_name { get; set; }
}
public class Setting_Master
{
public int _Id { get; set; }
public string _Name { get; set; }
public string _Code{ get; set; }
public string _Date { get; set; }
public Master_general _Mst_gen { get; set; }
}
}
---------------
in the above entity class,
i ve created object for Setting_Master [2nd class],
but i could not able to access last property in that, since its class Master_general property [this class is above but within same namespace]
...below is the code i am trying access , all the properties in class Setting_Master
Setting_Master obj_inner_structure = new Setting_Master();
obj_inner_structure._Mst_gen.Master_Static_Id =1;
here in above line error is thrown : Object reference not set to an instance of an object.
since Master_general is different class ......
D Company replied to anbu n on 17-Mar-12 02:18 AM
Hello,
The error is very obvious, u can't assign the property like this. to do so u have to implement the inheritance. inherit the class and do so.
Regards
D
kalpana aparnathi replied to anbu n on 17-Mar-12 06:57 AM
hi,
This error is obvious but got it to work by adding virtual keyword to the parent class
Regards,