c# 中的成员列表

本文关键字:成员 列表 | 更新日期: 2023-09-27 18:34:23

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;}
       }
     }

我在一个班级中有 25 个公共成员,当我制作该类的 IList 时,我会得到所有成员。我只希望特定的 5 个成员成为该 IList 的一部分,因为当我将该 ilist 转换为数据表时,我得到了 25 列,但我只希望在数据表中有 5 列。

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

提前谢谢。

<T> c# 中的成员列表


如果要从映射到数据库时排除某些属性,则必须对这些属性应用特殊属性。属性取决于用于处理数据库的工具。

例如,如果使用实体框架,则应将 [NotMapped] 属性设置为 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; }
}

如果使用 DevExpress XPO - 则应使用 [NonPersistent] 属性。
我希望 - 这将解决你的问题。