cast DataRow to Table

3 views
Skip to first unread message

jev...@geimanen.com

unread,
Nov 24, 2008, 3:03:10 AM11/24/08
to DbLinq
Hey all,

I wonder if anyone has meat same problem I did:

When I'm trying to select joining 3 tables, ASP.NET throws an
exception somewhere in Linq's expression.
So I decided to move that logic into Mysql stored procedure, which
returns to DBLinq DataSet and the problem I meat is to cast DataRow to
my table entity. I've used little bit of reflection to solve this
problem, but not sure it's best solution.

protected static Object initiateFromDataRow(DataRow row,Type
type)
{
Object res = type.GetConstructor(new Type[] { }).Invoke
(null);
PropertyInfo[] infos = type.GetProperties();
foreach (PropertyInfo info in infos)
{
if ((info.GetCustomAttributes(typeof(ColumnAttribute),
true)).Count() > 0)
info.SetValue(res, row[info.Name], null);
}
return res;
}

Any comments?

Thank you in advance.

Pascal Craponne

unread,
Nov 24, 2008, 1:33:52 PM11/24/08
to dbl...@googlegroups.com
Yes: what is your request? What exception do you get?
--
Pascal.

jabber/gtalk: pas...@jabber.fr
msn: pas...@craponne.org

jev...@geimanen.com

unread,
Nov 25, 2008, 7:39:12 AM11/25/08
to DbLinq
My development is far away from this problem. Have no time and don't
see meaning to reproduce it again, because the problem is in my mono's
version incompatibility.
The main topic of this post was actually the question of what is the
best way for casting DataRow to one of my Entities? (under entity I
mean [Table(...)] class like in dblinq examples)
I also brought my way, of how I am doing it at the moment, hoping that
google will help to someone in the future with same problem I had ;)

Pascal Craponne

unread,
Nov 25, 2008, 7:57:01 AM11/25/08
to dbl...@googlegroups.com
Considering this, I guess that the solution you already wrote is the best for now.
Reply all
Reply to author
Forward
0 new messages