M
Microsoft Public Groups
Hi,
I am trying to find a way of accessing a custom attribute defined on a field
from the actual field reference as opposed to the symbolic name of the
field. As that probably doesn't make sense I will show what I am trying to
do:
class SomeDatabaseObject : DatabaseObject
{
void Query()
{
......
BindParameter(id, sqlCommand);
......
}
[DatabaseAttribute("id", "@id", System.Data.SqlDbType.Int,
AttributeType.Key, 4)]
private int id;
}
The class DatabaseObject defines a BindParameter() method that will create
the binding and set the value in the SqlCommand object using the information
defined on the custom attribute class DatabaseAttributeAttribute. This way
if the DBA goes and changes the name of the column or SP parameter name I
can just update the DatabaseAttribute attribute on id.
My problem is in the implementation of BindParameter(object obj, SqlCommand
sqlComm) I need to be able to retrieve the custom attribute on the id field,
but I can only find a way of doing this symbolically, which is what I am
trying to avoid. I could add another parameter to the DatabaseAttribute
which is the symbolic name and change the BindParameter signature to
BindParameter(string fieldName, SqlCommand sqlComm) calling it via:
BindParameter("id", id, sqlCommand);
instead, this seems redundant and errors cannot be caught at compile time.
Any ideas would be appreciated.
Cheers,
Nic
I am trying to find a way of accessing a custom attribute defined on a field
from the actual field reference as opposed to the symbolic name of the
field. As that probably doesn't make sense I will show what I am trying to
do:
class SomeDatabaseObject : DatabaseObject
{
void Query()
{
......
BindParameter(id, sqlCommand);
......
}
[DatabaseAttribute("id", "@id", System.Data.SqlDbType.Int,
AttributeType.Key, 4)]
private int id;
}
The class DatabaseObject defines a BindParameter() method that will create
the binding and set the value in the SqlCommand object using the information
defined on the custom attribute class DatabaseAttributeAttribute. This way
if the DBA goes and changes the name of the column or SP parameter name I
can just update the DatabaseAttribute attribute on id.
My problem is in the implementation of BindParameter(object obj, SqlCommand
sqlComm) I need to be able to retrieve the custom attribute on the id field,
but I can only find a way of doing this symbolically, which is what I am
trying to avoid. I could add another parameter to the DatabaseAttribute
which is the symbolic name and change the BindParameter signature to
BindParameter(string fieldName, SqlCommand sqlComm) calling it via:
BindParameter("id", id, sqlCommand);
instead, this seems redundant and errors cannot be caught at compile time.
Any ideas would be appreciated.
Cheers,
Nic