Skip to content

Instantly share code, notes, and snippets.

@pmrozik
Last active August 29, 2015 14:13
Show Gist options
  • Save pmrozik/98afa8e0b59910049806 to your computer and use it in GitHub Desktop.
Save pmrozik/98afa8e0b59910049806 to your computer and use it in GitHub Desktop.
insertWords method
// Put all the words from the dictionary file in the database
public static void insertWords(List<string> wordList)
{
OperationDataContext odContext = new OperationDataContext();
int wordID = 0;
foreach (string word in wordList)
{
english_dictionary dictionary = new english_dictionary();
word.Trim();
// Check whether word is already in dictionary
var queryWords = from dword in odContext.GetTable<english_dictionary>()
where dword.word == word
select dword;
if(queryWords.Count() > 0)
{}
else
{
Console.WriteLine("Adding {0}....", word);
dictionary.word = word;
dictionary.wordID = wordID++;
odContext.english_dictionaries.InsertOnSubmit(dictionary);
}
}
odContext.SubmitChanges();
Console.WriteLine("Database insert operations complete.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment