SharePoint world of ECM and Information Management

.NET Tips: Data Access

back to content

INFO: 

  • |DataDirectory| (enclosed in pipe symbols) is a substitution string or substitution token that can be used in conjunction with AttachDbFileName in connection strings to indicate a relative path to a data source. It allows you easily deploy your Tables without installing it on SQLServer. For example "AttachDbFileName=|DataDirectory|\app_data\Northwind.mdf;integrated security=true;database=Northwind".  
  • DataSet/DataTable.ReadXml hinders performance if you not use ReadXmlSchema before, because CLR needs to create DOM structure from xml file before loading data.
  • Set DataSource propery last, to avoid control to be repopulated.
  • Use the SqlDataSource.EnableCaching to avoid redundant request to the underlying database and use cache. Request to DB will be performed only when DB changes. Don't use this with the user's security, because all users will have access to the cached data without rights validation

TIPS: 

  • User .Cast<T> to convert non-generic collection to generic one to use LINQ agains this new collection. >>
  • To have a LINQ support on .NET 2.0 project add the System.Core reference to your solution. >>
  • To query the ArrayList via LINQ you need to use Cast<T> your collestion in SELECT request. >>
  • .ToList() method allows you collection survive GC after u used it inside using structure >>
  • To share var across all methods you may use custom overload method, which returns you your anonymous type on the top >>
  • use ".Include()" method to get data by eager loading or use .Load() to get specific referenced data


 

back to content

Leave a Comment

(required) 

(required) 

(optional)

(required)