System.Data.DataTable 的轻量级替换
表格数据作为分隔数据存储在数据库中。我知道这并不理想,但这就是系统的设计方式。我需要提取数据并将其解析为某种结构。
在过去,我会使用 DataTable 并认为它很好。然而现在,这感觉很肮脏。什么是更好、更高效、更轻量级的结构来在我的数据模型中存储表格数据?
There is tabular data that is being stored in the database as a delimited data. Not ideal, I know, but that's how the system was designed. I need to pull the data out and parse it into some kind of structure.
In the old days, I'd use a DataTable and call it good. Now, however, that just feels dirty. What is a better, more efficient, and more lightweight structure to store tabular data in my data model?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是来自 Telerik 开发人员之一的轻量级数据表:
http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight-datatable-for-your-silverlight-applications.aspx
它支持 INotifyCollectionChanged 和 INotifyPropertyChanged 所以它非常适合数据绑定。
我不会说它不那么“肮脏”,但它是一种替代方案。
Here's a lightweight DataTable from one of the Telerik developers:
http://blogs.telerik.com/vladimirenchev/posts/09-04-23/lightweight-datatable-for-your-silverlight-applications.aspx
It supports INotifyCollectionChanged and INotifyPropertyChanged so it works well for data binding.
I wouldn't say it's any less "dirty", but it is an alternative.
好吧,只需创建一个将数据库的所有列作为属性的类即可。然后只需实例化 ICollection 的实现(List、Hashset 等)并填充它(例如使用 LINQ)。
并执行以下操作:
如果您正在访问存储在数据库中的数据,您可能需要查看 LinqToSql 或 LinqToEntities。
Well, just create a class that has all the columns of the database as properties. Then just instantiate an implementation of ICollection (List, Hashset, etc..) and fill it (using LINQ for example).
And do something like:
If you are accessing data that is stored in a database you may want to look at LinqToSql or LinqToEntities.
好吧,使用我开发的一个库,它包括类型到类型的转换等等,以及用于列出的数据读取器
https://www.nuget.org/packages/Generic.LightDataTable/
Well use a library i developed it include type to type convert and many more, and datareader to list
https://www.nuget.org/packages/Generic.LightDataTable/