缓存Linq的mappingSource,提高Linq To SQL的性能,(20%的性能都不至哟)

关键对象AttributeMappingSource

 

        [TestMethod]
        public void TestMethod1()
        {
            AttributeMappingSource source = new AttributeMappingSource();
            for (int i = 0; i < 10000; i++)
            {

                //AttributeMappingSource source = new AttributeMappingSource();--》去掉注释试试性能

                HRDataContext context = new HRDataContext(connString, source);
                var emp = context.GetTable<HR_Employee>().Where(p => p.EmployeeId == 10);

            }
        }

  

只要static一下AttributeMappingSource,每次使用就可以了

posted @ 2012-05-16 15:43  I'm CY  阅读(240)  评论(0编辑  收藏  举报