473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Object relational mapping via attributes?

I'd like to create a class with public properties and functions that I
can map into a datatable with corresponding fields. For example:

ClassA
string Name {get;set;}
int Age{get;set;}
boolean IsEmployed()

MyDataTable
Name
Age
IsEmployed

Can attributes be used above each class property and function such as:
[Name="Age" DataType="System.Int32"]

and how would I then inspect that information to create the DataTable?

Thanks,
Brett

Aug 30 '06 #1
9 2960
Brett Romero escribió:
I'd like to create a class with public properties and functions that I
can map into a datatable with corresponding fields. For example:

ClassA
string Name {get;set;}
int Age{get;set;}
boolean IsEmployed()

MyDataTable
Name
Age
IsEmployed

Can attributes be used above each class property and function such as:
[Name="Age" DataType="System.Int32"]

and how would I then inspect that information to create the DataTable?
I think you are reinventing the wheel. There is already an
object-relational framework which does this:

http://www.castleproject.org/index.php/ActiveRecord

Regards.

--

Aug 30 '06 #2
Actually, there is an even more .NET - friendly implementation of
ActiveRecord on the CodePlex site, written for ASP.NET 2.0, and very nicely
done, I might add. In fact, I had started writing a SQLite DataProvider for
it.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Brett Romero" wrote:
I'd like to create a class with public properties and functions that I
can map into a datatable with corresponding fields. For example:

ClassA
string Name {get;set;}
int Age{get;set;}
boolean IsEmployed()

MyDataTable
Name
Age
IsEmployed

Can attributes be used above each class property and function such as:
[Name="Age" DataType="System.Int32"]

and how would I then inspect that information to create the DataTable?

Thanks,
Brett

Aug 30 '06 #3
"Brett Romero" <ac*****@cygen.coma écrit dans le message de news:
11**********************@i3g2000cwc.googlegroups.c om...

| I'd like to create a class with public properties and functions that I
| can map into a datatable with corresponding fields. For example:
|
| ClassA
| string Name {get;set;}
| int Age{get;set;}
| boolean IsEmployed()
|
| MyDataTable
| Name
| Age
| IsEmployed
|
| Can attributes be used above each class property and function such as:
| [Name="Age" DataType="System.Int32"]
|
| and how would I then inspect that information to create the DataTable?

IMO, this is a very poor way of doing things as it "pollutes" the business
class space with database information. Using reflection, it is so simple to
iterate through the properties of any class, from the persistence layer, and
create your mappings there without altering the definition of your business
class.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Aug 30 '06 #4
>Using reflection, it is so simple to
iterate through the properties of any class, from the persistence layer, and
create your mappings there without altering the definition of your business
class.
Yes, reflection is easy but it is super slow.

Brett

Aug 31 '06 #5
Hi Brett,

I would recommend you to use the ObjectMapper .NET.

In opposite to NHibernate you can tag your properties with attributes
in order to do the object mapping. It's a very fast implementation, so
you don't have to fear about performance problems.

Furthermore you can create DDL files out of your business entities. I
think that's the thing you're looking for.

So have a look at http://www.objectmapper.net
or http://blog.objectmapper.net

Cheers
Gerhard

Brett Romero schrieb:
I'd like to create a class with public properties and functions that I
can map into a datatable with corresponding fields. For example:

ClassA
string Name {get;set;}
int Age{get;set;}
boolean IsEmployed()

MyDataTable
Name
Age
IsEmployed

Can attributes be used above each class property and function such as:
[Name="Age" DataType="System.Int32"]

and how would I then inspect that information to create the DataTable?

Thanks,
Brett
Aug 31 '06 #6
"Brett Romero" <ac*****@cygen.coma écrit dans le message de news:
11**********************@m79g2000cwm.googlegroups. com...

| Yes, reflection is easy but it is super slow.

Not if you do the reflection, to create the mappings, once on first use of
any class and then cache the results.

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Aug 31 '06 #7
| Yes, reflection is easy but it is super slow.
>
Not if you do the reflection, to create the mappings, once on first use of
any class and then cache the results.
How do you mean to cache those?

BTW, what is DDL?

Thanks,
Brett

Aug 31 '06 #8
"Brett Romero" <ac*****@cygen.coma écrit dans le message de news:
11*********************@i42g2000cwa.googlegroups.c om...

|| Yes, reflection is easy but it is super slow.
| >
| Not if you do the reflection, to create the mappings, once on first use
of
| any class and then cache the results.
|
| How do you mean to cache those?

You only need to read the PropertyInfo for a given type once to determine
what properties are available; so the first time that you start the program,
build a list of mappings from the business class types to their tables and
stream that list to something like a database or XML file. then, subsquent
executions of your program only need to recreate the mappings from the
stored stream, instead of using reflection all over again.

| BTW, what is DDL?

DDL = Data Definition Language

Joanna

--
Joanna Carter [TeamB]
Consultant Software Engineer
Aug 31 '06 #9
<ge*************@googlemail.comwrote:
I would recommend you to use the ObjectMapper .NET.
Just thought it would be worth pointing out for the record that this
isn't exactly an unbiased recommendation - the author of the post is
the author of ObjectMapper .NET, according to another post.

<snip>

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 21 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Krzysztof Stachlewski | last post by:
I tried to run the following piece of code: Python 2.3.4 (#53, May 25 2004, 21:17:02) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> o = object() >>> o.a...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
18
by: comcast | last post by:
Hello all, I am developing an interface system for an application I was written. This interface will connect to other system to share information. I would like to use xml and xsl to generically...
0
by: Olivier Jullian | last post by:
Hi, I'm new to .NET and am trying to take advantage of the object structure while accessing relational databases. I started a small project for managing "projects". Here is a description of...
2
by: object-relational persistence mapping | last post by:
Someone can tell me where I find a good Object-Relational Mapping library.
5
by: DraguVaso | last post by:
Hi, I'm ne to this subject, and has been looking around for some software that does the Object-Relational-Mapping, and generates the Data Access Layer. I found alreaddy a lot of application that...
3
by: pratham | last post by:
If i understand correct? is strong typed DataSet is ORM implementation by Microsoft? Expecting comments .. please Praveen
3
by: dariosalvi78 | last post by:
Hi, I am exploring the object-relational mapping tools (the free ones) for the .net CF 2. As far as I have seen all the tools start from the tables of a database and generate code to build...
13
by: sulyokpeti | last post by:
I have made a simple python module to handle SQL databases: https://fedorahosted.org/pySQLFace/wiki Its goal to separate relational database stuff (SQL) from algorythmic code (python). A SQLFace...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.