Reputation: 19440
I have two entities called English and German. Both of them have the fields ID,Vocable.
To connect translations with each other I created the table GermanEnglish which holds the IDs of both of the first entities and the unit the vocable occured first in.
Inserting one vocable with multiple translations at once (before submitting the changes to the GermanEnglish-object) works fine. When I want to add a translation to an existing vocable, I get an error that this value is already in the database (I defined the Vocable-field as UNIQUE).
I tried the following:
using (VokabeltrainerDBDataContext context = new VokabeltrainerDBDataContext())
var german = from voc in context.German
where voc.GermanWord.Equals(txtVocable.Text)
select voc;
// if the german word exists in the database...
if (german.Any())
{
foreach ( English englishWord in englishTranslations)
{
var germanEnglish = new GermanEnglish();
germanEnglish.English = englishWord;
germanEnglish.Unit = unit;
germanEnglish.German.Add(german); // add-method not available!
context.GermanEnglish.InsertOnSubmit(germanEnglish);
}
} else {...}
context.SubmitChanges();
... but the Add-method isn't available. In all of the questions and tutorials I only see people using the add-method.
Do I have an error in my code? Or isn't this method available anymore? (like the Add-method that was renamed to InsertOnSubmit)
Upvotes: 0
Views: 378
Reputation: 5469
As far as I understand your example EnglishGerman
is table that has EnglishGermanID, Unit, EnglishID, GermanID
?
So you can't add List of German's. You can only assign germanEnglish.German = german
(in this case must be only one object)...I think so, but I'm little new in linq
Upvotes: 1