I am asking this question since I would like to know what is the best method of coding in a C # 2010 web form page that I just wrote. I read somewhere that everytime you need a datacontext object, you should create it. There was no reference also to removing
the datacontext object.
Thus on the current web form page that I am using that connects to a sql server 2008 r2 database, I am doing the following:
1. I never remove the AttDataContext from memory.
2. On the same web page, I am referring to the same linq to sql *.dbml file. However depending upon what I user clicks on, I have the following 3 datacontext objects:
a. AttDataContext,
b. Att2DataContext,
c. Att3DataContext.
Can you tell me if the above if a good idea or not? If not, can you tell me how I should use the same data context object on the same web
Can you tell me if the above if a good idea or not? If not, can you tell me how I should use the same data context object on the same web
Yes I think you can use them dynamically because each data context maps to a different kind of database with tables;But in order to make this more flexiable,I prefer to use DataSet+DataTables,this will let you dynamically create them and use。
Reguards!
Marked as answer by cindy gal on Jul 11, 2012 01:44 AM
cindy gal
Member
45 Points
86 Posts
linq to sql data context issue
Jul 08, 2012 03:52 PM|LINK
I am asking this question since I would like to know what is the best method of coding in a C # 2010 web form page that I just wrote. I read somewhere that everytime you need a datacontext object, you should create it. There was no reference also to removing the datacontext object.
Thus on the current web form page that I am using that connects to a sql server 2008 r2 database, I am doing the following:
1. I never remove the AttDataContext from memory.
2. On the same web page, I am referring to the same linq to sql *.dbml file. However depending upon what I user clicks on, I have the following 3 datacontext objects:
a. AttDataContext,
b. Att2DataContext,
c. Att3DataContext.
Can you tell me if the above if a good idea or not? If not, can you tell me how I should use the same data context object on the same web
form page?
rickevry
Member
386 Points
88 Posts
Re: linq to sql data context issue
Jul 08, 2012 06:35 PM|LINK
cindy gal
Member
45 Points
86 Posts
Re: linq to sql data context issue
Jul 08, 2012 06:44 PM|LINK
I am using the datacontext in the following locations:
1. On the Page_load when (!IsPostBack),
2. I am also using the datacontext when the user clicks the 'next' button to update the database on web page 1 and web page 2.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: linq to sql data context issue
Jul 10, 2012 01:35 AM|LINK
Yes I think you can use them dynamically because each data context maps to a different kind of database with tables;But in order to make this more flexiable,I prefer to use DataSet+DataTables,this will let you dynamically create them and use。
Reguards!