none
How to use Partial Class to add Calculated Field into Entity? RRS feed

  • Question

  • Hi all,

    Let say I have a class Customer entity created by LINQ. Now I want to add a custom fields / methods inside, so I intented to use Partial Class to extend the Customer Class.

    I tried to create a Partial Class. Let me show a code snippet. The following code is generated by LINQ:
        [Table(Name="dbo.Customer")]
        public partial class Customer : INotifyPropertyChanging, INotifyPropertyChanged
        {
            private string _name;
            ...
            [Column(Storage="_name", DbType="VarChar(40) NOT NULL", CanBeNull=false)]
            public string name
            {
                ....
            }
        }

    So I created another Partial Class for Customer:
        public partial class Customer
        {
            public string upperName
            {
                get { return ToUpperCase(name); }      // Can't access "name" property here !!!
            }
        }

    How to solve the problem?

    Thank you very much.

    Best regards,
    Diviner.
    Wednesday, July 23, 2008 11:30 AM

Answers

  • Are you sure the partial class you created is in the same namespace?

     

    If you are using the Designer, you can simply right-click on the entity (Customer) and select 'View Code'. This will bring up the code editor with an outline of the partial class, and you can then add members to it.

     

    Hope that helps,

     

    --Samir

     

     

    Wednesday, July 23, 2008 4:30 PM

All replies

  • Are you sure the partial class you created is in the same namespace?

     

    If you are using the Designer, you can simply right-click on the entity (Customer) and select 'View Code'. This will bring up the code editor with an outline of the partial class, and you can then add members to it.

     

    Hope that helps,

     

    --Samir

     

     

    Wednesday, July 23, 2008 4:30 PM
  • Samir,

    Yes, actually it is my mistake on NameSpace. I am still not familiar in .NET.  

    Thank you very much.
    --
    Best regards,
    Diviner.
    Thursday, July 24, 2008 4:59 AM