Attributes with Database info

Attributes with Database info

Old forum URL: forums.lhotka.net/forums/t/6713.aspx


byle posted on Wednesday, April 01, 2009

Hello!

I'm developing an application for Compact Framewrok 3.5 with CSLACe.
The case is that I am filling the dataportal_XYZ methods with direct queries to DB using SQLCECommands and others.
Using this, means to hard-code the table and column names directly to the query.
So to not hardcode it, I've thought to create simple attributes to bind a class with a table name and a property with a column name like this:


[DatabaseTable("PROJECTS")]
public class Project : BusinessBase
{

[DatabaseColumn("PROJECTID")]
public Int64 Id
{ get; set; }

}


Where queries from the class Project should point to the table "PROJECTS" and property Id should point to the column "PROJECTID".

That's the general idea. But before implementing anything I would like to know if CSLACE does have some similar functionality or if anyone knows any better idea.

Thanks a lot!

Greetings!!

RockfordLhotka replied on Wednesday, April 01, 2009

I don't believe it does. CSLA CE is based on the CSLA .NET 3.0 codebase, which pre-dates the new PropertyInfo<T> syntax. The new PropertyInfo<T> syntax allows you to attach metadata to a property without resorting to reflection.

You can absolutely do what you describe. Just be aware that the reflection calls to retrieve custom attribute data are among the most expensive reflection calls you can make. Due to this, you'll probably want to figure out a way to do the reflection once and cache the results for the lifetime of the application.

byle replied on Thursday, April 02, 2009

OK, I'll create a cache to store all read attributes. Thanks a lot for the advice!

Copyright (c) Marimer LLC