Typed Dataset not using TypedTableBase in .NET 4

后端 未结 3 571
面向向阳花
面向向阳花 2020-12-21 02:20

I\'m migrating our DAL class library to .NET 4 (from .NET 3.5). We\'re using typed datasets quite often, and we often iterate over tables:

foreach(var row in         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-21 03:02

    All this is correct but in my case I had to support source code which needs to run with .Net 2.0 and .Net 4.0. My objective was to change as little code as possible.

    My solution was to create a partial extension under .Net 4.0 and bind it to the 4.0 application. This looks like:

    namespace NamespaceOfMyDataSet
    {
        public partial class MyDataSet : global::System.Data.DataSet 
        {
            public partial class MyTypedTable : global::System.Data.TypedTableBase 
            {
                public System.Data.DataRowCollection GetRows()
                {
                    return this.Rows;
                }
            }
        }
    }
    

    This works like a charme!!!

提交回复
热议问题