How to get rid of strongly typed tables and data

In our organization, we maintain the VS 2005 website, which relies heavily on strongly typed tables and data. It goes without saying that this is a nightmare for repairability for many reasons:

  • To create new table adapters, we need to connect to the MSSQL2005 database and less, and since we upgraded our database to MSSQL2008, this is really hell.
  • We are at the end of 2010, and we really like to use VS2010 for this project, but updating it will not be compromised. I think we could work to make this work, but we'd better get rid of this terrible technology.
  • The generated code is huge and looks awful, and I doubt anyone can understand it without something like LSD.

At this stage, we really would like to do the minimum to help us get rid of these table adapters, because we do not have time, and this is less priority for management, because it "works". Therefore, the nHibernate proposal is a revolution that we probably will not overtake.

Thanks in advance.

+3
source share
2 answers

VS 2005 DataSet TableAdapters. VS 2008 - , 2010 - . , 2010 , , - DataSets, .

2008 , 2010 . , , DAL...

+2

Delucia,

, / , , , , , .:)

, , , , .

    /// <summary>
///This class is a wrapper around a DataTable,
///Associated with the stored procedure - usp_GET_FEATURES
///This class provides a strongly typed interface to access data from the DataTable
///containing the result of the given stored procedure.
/// </summary>
public class FeaturesDtw : BaseDataTableWrapper
{
    public Int32 Id { get { return (Int32)DataRow[0]; } }
    public String Title { get { return (String)DataRow[1]; } }
    public String ShortDesc { get { return (String)DataRow[2]; } }
    public String Description { get { return (String)DataRow[3]; } }
    public String ImageFilePath { get { if (DataRow[4] != DBNull.Value) return (String)DataRow[4]; else return default(String); } }
    public String ImageFileName { get { if (DataRow[5] != DBNull.Value) return (String)DataRow[5]; else return default(String); } }
    public String ImageMimeType { get { if (DataRow[6] != DBNull.Value) return (String)DataRow[6]; else return default(String); } }
    public DateTime DateCreated { get { return (DateTime)DataRow[7]; } }

    public FeaturesDtw()
        :base()
    {
    }

    public FeaturesDtw(DataRow row)
        :base(row)
    {
    }
}

, , DataTable. , DataTable , , proc .

:

  var dt = DataModule.GetFeaturesDataSet().Tables[0];
  FeatureDtw featureDtw = new FeatureDtw();
  foreach(DataRow row in dt.Rows)
  {
    featureDtw.DataRow = row;
    var id = featureDtw.Id;
    var title = featureDtw.Title;
  }

DataTab ( dt) DAL, , .

private IEnumerable<T> GetEnumerableDtw<T>(DataTable dt) where T : BaseDataTableWrapper, new()
{
  foreach (DataRow row in dt.Rows)
  {
    var baseDataTableWrapper = new T();
    baseDataTableWrapper.DataRow = row;
    yield return baseDataTableWrapper;
  }
}

dt IEnumerable, , IEnumerable, , DataTable.

. , , DataTable , .

, ?

    /// <summary>
///This class Base Class for all DataTable Wrappers
/// </summary>
public class BaseDataTableWrapper
{
    public DataRow DataRow { get; set; }

    public BaseDataTableWrapper()
    {
    }

    public BaseDataTableWrapper(DataRow row)
        :this()
    {
        DataRow = row;
    }
}
+1

Source: https://habr.com/ru/post/1773644/


All Articles