2012-10-06 44 views

回答

1

映射:

Map(x => x.Word).Unique(); // just to make sure it is unique 

代碼:

void AddWords(ICollection<string> words) 
{ 
    var existingWords = session.QueryOver<UniqueWord>() 
     .WhereRestrictionOn(w => w.Word).In(words) 
     .Select(w => w.Word) 
     .List<string>(); 

    foreach(var word in words.Except(existingWords)) 
    { 
     session.Save(new UniqueWord(word)); 
    } 
    session.Flush(); 
}