IList<T> member list in c#

211 Views Asked by At
public class Session
{ 
    --private properties
     private string p1;
     private string p2;
     private string p3;
     .
     .
     .
     .
     private string p25;


     --public properties
      public string P1
      {
        get { return p1;}
        set{p1=value;}
      }
      .
      .
      .
      .
      public string P25
      {
       get { return p25;}
       set{p25=value;}
       }

     }

I have 25 public members in a class and when I make a IList of that class I get all the members . I want only specific 5 members to be part of that IList Because when i convert that ilist to datatable i get 25 columns but i want only 5 columns in datatable.

IList<Session> listSessionAttachment = new List<Session>();

Thanks in advance.

1

There are 1 best solutions below

0
KolobOKs On


If you want to exclude some properties from mapping to your database, you have to apply special attributes to these properties. Attributes depend on the tools you use to work with the database.

For example, if you use Entity Framework, you should set [NotMapped] attribute to proprety.

public class MyClass
{
    [NotMapped]
    public String Str1 { get; set; } // this property will not be a column in MyClass table
    public String Str2 { get; set; }
    public String Str3 { get; set; }
}

If you use DevExpress XPO - you should use [NonPersistent] attribute.
I hope - this will solve your problem.