reading ColumnAttribute data

L

lausivcid

Hi,

How can ColumnAttribute data be read from xxDataClasses.cs 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.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}


Attribute.GetCustomAttribute(this.Name.GetType().Module,typeof(System.Data.Linq.Mapping.ColumnAttribute))
returned null,
Attribute.GetCustomAttributes(this.Name.GetType().Module) returned
only the System.Security.UnverifiableCodeAttribute 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
 
N

Nicholas Paldino [.NET/C# MVP]

lausivcid,

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


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

in message
news:[email protected]...
 
L

lausivcid

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.OnNameChanging(value);
this.SendPropertyChanging();
this._Name = value;
this.SendPropertyChanged("Name");
this.OnNameChanged();
}
}
}

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().GetMembers())
{
string attrib=
((System.Data.Linq.Mapping.ColumnAttribute)(mi.GetCustomAttributes(false)[0])).DbType;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top