Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 10th, 2011, 05:48 PM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default How many linq-to-SQL datacontexts per solution? I get the “menber is defined more tha

Hi,

I get the “menber is defined more than once” error. 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.
 
Old January 11th, 2011, 01:57 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Can you please post questions that are not directly related to this book in a more general ASP.NET category here: http://p2p.wrox.com/asp-net-asp-12/ ? Makes it easier for others to join and learn from the discussion.

Anyway, you can differentiate types in different DBML files by setting the Entity Namespace property of the model (click the design surface and then press F4).

However, with only 15 tables, I would add them all to a single DBML file.

Code:
 
and then always use the same datacontext throughout the project.
The same datacontext *type*, not the actual instance. That is, you want to "new" up a context in each page, and not use a global one that all your pages use.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
scrx (January 11th, 2011)
 
Old January 11th, 2011, 02:11 PM
Registered User
 
Join Date: Oct 2010
Posts: 3
Thanks: 1
Thanked 0 Times in 0 Posts
Default ok, thank you for your reply.

ok, thank you for your reply.





Similar Threads
Thread Thread Starter Forum Replies Last Post
LINQ to SQL or not? gvdamn BOOK: Professional DotNetNuke Module Programming ISBN: 978-0-470-17116-5 2 August 20th, 2009 05:08 AM
LINQ to SQL bakm04 BOOK: Professional C# 2008 ISBN: 978-0-470-19137-8 0 August 17th, 2009 04:07 PM
LINQ to SQL in TheBeerHouse zhoux BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 October 1st, 2008 07:37 AM
Dealing with the presence of an XML tag rather tha Mike250 SQL Server 2005 1 June 6th, 2008 03:50 PM
using Sql server 2000 with LINQ shashanksinha SQL Server 2000 2 August 20th, 2007 10:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.