reading ColumnAttribute data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lausivcid

    #1

    reading ColumnAttribute data

    Hi,

    How can ColumnAttribute data be read from xxDataClasses.c s Columns
    like this?

    [Column(Storage= "_Name", DbType="VarChar (256) NOT
    NULL", CanBeNull=false )]
    public string Name
    {
    get
    {
    return this._Name;
    }
    set
    {
    if ((this._Name != value))
    {
    this.OnNameChan ging(value);
    this.SendProper tyChanging();
    this._Name = value;
    this.SendProper tyChanged("Name ");
    this.OnNameChan ged();
    }
    }
    }


    Attribute.GetCu stomAttribute(t his.Name.GetTyp e().Module,type of(System.Data. Linq.Mapping.Co lumnAttribute))
    returned null,
    Attribute.GetCu stomAttributes( this.Name.GetTy pe().Module) returned
    only the System.Security .UnverifiableCo deAttribute attribute.
    Specifically I want to parse DbType to get the maximum length of the
    column. Is there any other way to find the column width?

    Thanks,
    lausivcid
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: reading ColumnAttribute data

    lausivcid,

    Well, you have applied the attribute to a property, so you have to get
    the PropertyInfo for that property (Name) and then call GetCustomAttrib utes
    on that.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "lausivcid" wrote in message
    news:ucuih31ivh cp1qpa4jo5bd6gf ofis1jn5m@4ax.c om...
    Hi,
    >
    How can ColumnAttribute data be read from xxDataClasses.c s Columns
    like this?
    >
    [Column(Storage= "_Name", DbType="VarChar (256) NOT
    NULL", CanBeNull=false )]
    public string Name
    {
    get
    {
    return this._Name;
    }
    set
    {
    if ((this._Name != value))
    {
    this.OnNameChan ging(value);
    this.SendProper tyChanging();
    this._Name = value;
    this.SendProper tyChanged("Name ");
    this.OnNameChan ged();
    }
    }
    }
    >
    >
    Attribute.GetCu stomAttribute(t his.Name.GetTyp e().Module,type of(System.Data. Linq.Mapping.Co lumnAttribute))
    returned null,
    Attribute.GetCu stomAttributes( this.Name.GetTy pe().Module) returned
    only the System.Security .UnverifiableCo deAttribute attribute.
    Specifically I want to parse DbType to get the maximum length of the
    column. Is there any other way to find the column width?
    >
    Thanks,
    lausivcid

    Comment

    • lausivcid

      #3
      Re: reading ColumnAttribute data

      Thanks! For

      [Column(Storage= "_Name", DbType="VarChar (256) NOT
      NULL", CanBeNull=false )]
      public string Name
      {
      get
      {
      return this._Name;
      }
      set
      {
      if ((this._Name != value))
      {
      this.OnNameChan ging(value);
      this.SendProper tyChanging();
      this._Name = value;
      this.SendProper tyChanged("Name ");
      this.OnNameChan ged();
      }
      }
      }

      The class tyoe for this property is "job". The below code gets the
      DbType string I am looking for.

      foreach (MemberInfo mi in
      job.GetType().G etMembers())
      {
      string attrib=
      ((System.Data.L inq.Mapping.Col umnAttribute)(m i.GetCustomAttr ibutes(false)[0])).DbType;
      }


      On Sat, 20 Oct 2007 13:02:56 -0400, "Nicholas Paldino [.NET/C# MVP]"
      <mvp@spam.guard .caspershouse.c omwrote:
      >lausivcid,
      >
      Well, you have applied the attribute to a property, so you have to get
      >the PropertyInfo for that property (Name) and then call GetCustomAttrib utes
      >on that.

      Comment

      Working...