Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jun 10, 2009 06:22 PM by kf7
Jun 09, 2009 03:14 PM|LINK
Ive just started using LINQ and am having a few problems. Ive created a separate data access layer with a .dbml file for my database. When I try to reference the LINQ functionality from within my business layer, not all the properties and methods are
heres how ive structured my app
DataAccessLayer with OnlineOrder.dbml
Business layer that references the data access layer,
Ive created a method for inserting a record into a table (Publications) from within the business layer, so Ive created an instance of the LINQ data context object, but none of its properties and methods are available
public class PublicationBLManager
public string add(DataAccessLayer.Publication publication, string dbfunction)
DataAccessLayer.LeafletOrderingDataContext leafletcontext = new DataAccessLayer.LeafletOrderingDataContext();
DataAccessLayer.Publication newPublication = new DataAccessLayer.Publication();
string res = string.Empty;
leafletcontext.Publications-- code competion should show methods here, but nothing
. if (dbfunction == "Save")
If I try the same code inside the data access layer, all the methods are available (SubmitChanges, leafletcontext.Publications.Single, etc)
Am I going about this the wrong way ?? Id normally have a separate data access layer and just access the functions from my business layer
As I said, Im a complte newcomer to LINQ, so any help would be appreciated
Jun 09, 2009 03:16 PM|LINK
slight mistake with the above code, my DataAccessLayer contains LeafletOrdering.dbml NOT OnlineOrder.dbml
Jun 09, 2009 03:49 PM|LINK
I also get a compiler error on this line
Error 6 The type 'System.Data.Linq.DataContext' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089'. C:\DWPProjects\LeafletOrderingOnline\BusinessLogicLayer\PublicationBLManager.cs 18 13 BusinessLogicLayer
There is no System.Data.Linq assembly
Jun 09, 2009 11:22 PM|LINK
Try adding reference to System.Data.Linq.
Right click on the project, choose Add Reference. Under .NET tab, select System.Data.Linq
Jun 09, 2009 11:32 PM|LINK
Regarding your first problem. Because you are using different layers, you need to make sure that your namespaces are correct. In the properties of LINQ to SQL you can define the namespace. It will help you structure your objects properly.
I didnt get it, you cant see any methods or any table column names.
If you cant see any methods, it could be because you are missing a reference.
If you cant see column names: You wont be able to any table columns like this. The following line wont show you anything.
var pubs = leafletcontext.Publications.Select(q => q.columnname);
Jun 10, 2009 08:22 AM|LINK
adding a refernce to System.Data.Linq fixed my problem, I now have a bunch of properties and methods available, with one notable exception. There is no 'Add' method !
The underlying table has a primary key (an identity column)
Any ideas why the 'Add' is missing ?
Jun 10, 2009 01:33 PM|LINK
sorry. i didnt get it. what is it that you are trying to do.
are you trying to add a record to your table?
Jun 10, 2009 06:00 PM|LINK
ive sorted it, i used InsertOnSubmit
The linq example I was following used an 'add' method ! not sure where the author got it from.
Jun 10, 2009 06:22 PM|LINK
Yea its InsertOnSubmit.
Anyways, good that its resolved.
Let me know if I can help you with something else.