Invalid Column Name
-
Wednesday, May 14, 2008 2:32 PM
I have a Linq Class that maps to a junction table say order_customer.
The lInq class is called CustomerOrder that has 3 properties :
CustomerId, OrderId, CustomerName
I fetch data to populate the linq class CustomerOrder using a stored proc that ties the junction table order_customer to customer table to get the customer name.
Now when I try to update the database by calling SubmitChanges on the relevant datacontext, I get an error that says Invalid Column Name. I know this is happening because it can't find a column for CustomerName. How do I tell my Linq class CustomerOrder to ignore that column/property while updating.
Any pointers?
thanks,
R
All Replies
-
Wednesday, May 14, 2008 3:08 PM
I hope I understood the issue correctly, sorry if i didn't. You can do so by going to the dbml designer, right clicking to CustomerName column and deleting the "source" property of it. This will let your CustomerName field not to be bound to that specific column in the db.
-
Wednesday, May 14, 2008 6:11 PM
Sidar,
I tried that but it does not seem to work!
R
-
Thursday, May 15, 2008 2:24 PM
Hi Ranji,
Sorry that it didnt help. Can you provide some sample code, may be a little project that demonstrates the problem you are having ?
-
Friday, June 06, 2008 9:08 AMModeratorAs there has been no response for the additional information I'm going to mark this thread as answered. If you are still having the problem and wish to continue the discussion just reopen the thread
[)amien -
Friday, June 06, 2008 6:01 PM
Very good. The response is that it did not work.
To re-create the problem create a linq to sql class that maps to a table in your database.
Add an additional property to your linq to sql class using the designer ; ensure that this property does not map to any specific column in the database table. remove the source property's value (i dont see this as required since it should be blank as it does not map to anything). now populate your linq to sql class's instance and submitchanges to save theobject to db. it craps out with the 'invalid column' error. it happens because it cannot find a column to save this additional property.
any input?
thanks.
-
Friday, June 06, 2008 6:33 PM
aha i see now - so you are adding this field through designer - now i am able to regenerate the error you are getting.
Designer generates a Column attribue automatically which during execution means that it is going to be mapped to a table column.
Just delete all column attribute associated to that property from designer.cs file manually, save it, and run it (without re-opening the designer. You'll see that the error will fade away (at least mine did)
But keep in mind that when you open the dbml designer and save, designer tool runs and overrides your changes so those attributes will come back. (which is something I hate, see my post about this: http://www.sidarok.com/web/blog/content/2008/06/04/linq-to-sql-wish-list.html . )
A better alternative is to keep additional methods in a partial class of that entity and implement your custom property in partial class. It also is better o keep your data concerned properties(mapped to columns) and the rest seperate.
hope this will work.
Sidar
-
Monday, June 09, 2008 11:50 PMModerator
Yes, the add property in the LINQ to SQL Classes designer is for adding properties that are specifically used and managed by LINQ to SQL and so you will get this error as LINQ to SQL does not have enough information to handle the property.
If you wish to add a property that is completely managed by yourself and not mapped in LINQ to SQL you can extend the partial class with your own code and nothing will be lost/overwritten.
[)amien
-
Wednesday, June 10, 2009 1:21 AM
By adding the property into another partial class works fine, but another issue raised.
The reason I want to add the custom property is to load the extra data from joined query like the following.
var
langs = (from tl in db.TutorsLanguages
join l in db.Languages on tl.LanguageCode equals l.LanguageCode
join pl in db.ProficiencyLevels on tl.ProficiencyLevelID equals pl.ProficiencyLevelID
where tl.TutorID.Equals(tutorID)
select new TutorsLanguage
{
TutorLanguageID = tl.TutorLanguageID,
TutorID = tl.TutorID,
LanguageCode = tl.LanguageCode,
ProficiencyLevelID = tl.ProficiencyLevelID,
LanguageName = l.LanguageName, // customer property
ProficiencyName = pl.ProficiencyName // customer property
});
but it gives me the following error:
Explicit construction of entity type 'Tien.iTutorNetwork.Entity.TutorsLanguage' in query is not allowed.
The table : TutorsLanguage reuiqres to have primary key, so the remove primary key method doesnt work for me.
Is there solutions other than creating a class inherite from the TutorLanguage. which someone report to work from this link
Thank you so much in advance.. -
Thursday, July 07, 2011 6:51 PM
I realize this thread is 2 years old, but I found it while looking for an answer when the problem occurred for me. Commenting out the code in designer.cs will resolve the error, but it also eliminates using the Column in the program.
My problem occurred because my designer.cs was using the updated DB I added a column to (in the project directory folder), however the DB my program was accessing (same names) was located in the Debug folder. This DB-Table did not have the column that was trying to be accessed. So my suggestion to future occurrences is to check that the program is accessing the correct DB.
Hope this helps,
TC
-
Friday, July 13, 2012 11:51 AMThank you good sir tysear. Saved my day.
- Edited by S3rR1 Friday, July 13, 2012 11:51 AM

