What is the most efficient standalone .NET class that can hold a single disconnected record? The class must also retain column names, but other schema is not relevant (.NET data type is sufficient).
If I understand System.Data.Common.DbDataRecord, it provides an interface on a DbDataReader, and has no storage of its own.
I'm familiar with DataSet, is that the only .NET-standard class to do this?
Thank you,
Shannon
Why not create a normal class with properties and fill it from a SqlDataReader, or use a OR-Mapper..?
|||I second N Frederick 's suggestiong, nothing will be faster (or easier) than a datareader populating a regular class
|||Thanks for your reply. If I understand correctly, you are suggesting that in most application-specific design scenarios, a strongly-typed class representing my scenario data object is proscribed? "normal class" assumes that I would benefit from get/set properties for myself to code against. And O/R mapper suggestion to accomplish the same.
I'm building a generic server control (an in-place editor with HTML client-side functionality). I just want something to do table-based forms against for now.
My comment that I need to store data type and column name result from the fact that I won't know at design-time (of the server control) what they are.
p.s. If you are aware of a free .NET library to do this already, I'm all ears.
TwasBrillig:
you are suggesting that in most application-specific design scenarios, a strongly-typed class representing my scenario data object is proscribed? "normal class" assumes that I would benefit from get/set properties for myself to code against. And O/R mapper suggestion to accomplish the same
Speaking for myself, I wouldn't overanalyze. The requirement you gave originally is very simple, so solve it with something very simple. OTOH....
TwasBrillig:
comment that I need to store data type and column name result from the fact that I won't know at design-time (of the server control) what they
that's a different story, if you don't know at design time what you're getting back then you can't put it in a predefined class. I suspect that your requirements are much more complex than yo've get on
dbland07666:
TwasBrillig:
you are suggesting that in most application-specific design scenarios, a strongly-typed class representing my scenario data object is proscribed? "normal class" assumes that I would benefit from get/set properties for myself to code against. And O/R mapper suggestion to accomplish the same
Speaking for myself, I wouldn't overanalyze. The requirement you gave originally is very simple, so solve it with something very simple. OTOH...
That's the second cryptic reply that implies in an offhand way that the answer is simple, but doesn't answer. I hear you, the answer is 42. But what does it mean? Sure I'd love to do something very simple; What is very simple to store one record, for goodness sake? A DataSet? That was my question.
dbland07666:
TwasBrillig:
comment that I need to store data type and column name result from the fact that I won't know at design-time (of the server control) what they
that's a different story, if you don't know at design time what you're getting back then you can't put it in a predefined class. I suspect that your requirements are much more complex than yo've get on
Not knowing the type is different from not knowing the structure. A record. One table record. Sure I can build a class myself to do it, I can iterate through columns and store Column-name:Object pairs in a dictionary list, and inspect later what type is in the box. No, my requirements aren't more complex. But my question is: Is there a class already in the .NET library to hold one record, one I can copy one record into with a single method call? When I'm done I have one record in storage, and can disconnect my DbDataReader and think about my one record, its columns' values, its columns' data types, and their names for as long as I like?
|||Here are the types in ADO.Net that you can use:
DataSet = Table, rows and columns, a disconnected resultset that more or less reflects a databas but in memory.
DataReader = Need a connection and will read a row on command, so it will only stay at a specific position and move to the next recoed when you ask it to do it. See it as a Row, Column based object.
You can also use DataSet with XML etc.
Then you can create your own classes (custom business objects "entities"), such as a Customer, Product etc.
In your case where you specify that you can't use a custom class, I think you should simply use a DataSet.
|||Thank you Fredrik, that absolutely answered my question. I appreciate you taking your time answering something so basic.
I felt like there must be another class out there that I had overlooked in the library, or some other magic to DbDataRecord that I wasn't aware of.
If I'm not mistaken, I could reliably use DataReader to access the current row after disconnecting it if I only ever asked it for the values, and not any schema information (such as column name or data type).
Thanks again!
No comments:
Post a Comment