I have a relational database with about 15 tables that will be used in 4 different aspx pages (for now). Each aspx page uses some of the tables, but never all tables at once: for instance, one page might use 4 tables while another page might use 6 tables. I started doing a dbml file for the first aspx file with just the 4 tables needed. When I got to the second aspx file, I did another dbml file with just the 6 tables that were needed for this aspx file. 2 of the tables are in both datacontext dbml files and I get a “member is defined more than once” error.
After reading some online posts, my question about dbml files is this: when using linq-to-SQL, for an application, can we create multiple dbml files with the same tables or do we have to do just one dbml file for the whole application because a table can only be in one dbml file. If the latter is the case, do we need to simply include every database table in the dbml file and then always use the same datacontext throughout the project.
Thanks.
The dbml file shouldn’t be the problem, but I guess you are using the designer, which automatically generates code – if you use two designers in the same namespace, the class names will collide. You’ve got three options then:
Personally, I always go with 3., because linq-to-sql does support lazy loading, ie. there will be no resources spent if you don’t query for any data.