private void ImportAuthors(ILibrary libManager) { IDConversionDao idcDao = new IDConversionDao(); AuthorDao authorDao = new AuthorDao(); var anotherDbAuthors = authorDao.FindAll(_dataOpUnit.CurrentConnection, s_ANOTHER_DATABASE_ALIAS_NAME).ToList().ToViewModel(); var authors = authorDao.FindAll(_dataOpUnit.CurrentConnection).ToList().ToViewModel(); //同ID x 同値:対象ライブラリのエンティティをインポートしない。 var alpha = from a in anotherDbAuthors join oa in authors on a.ID equals oa.ID where a.Name == oa.Name select a; //同ID x 異値:対象ライブラリのエンティティを新規IDでインポートする。取込側ライブラリに新規IDと旧IDを記録する。 var beta = from a in anotherDbAuthors.Except(alpha) join oa in authors on a.ID equals oa.ID where a.Name != oa.Name select a; foreach (var add in beta) { var newGuid = Guid.NewGuid(); idcDao.Insert(new Data.Entity.Migration.IDConversion("Author", newGuid, add.ID), _dataOpUnit.CurrentConnection); add.ID = newGuid; ImportAuthor(libManager, add); } //異ID x 同値:対象ライブラリのエンティティをインポートしない。取込側ライブラリに新規IDと旧IDを記録する。 var gamma = from a in anotherDbAuthors.Except(alpha).Except(beta) join oa in authors on a.Name equals oa.Name where a.ID != oa.ID select new { ForeignID = a.ID, DomesticID = oa.ID, Author = a }; foreach (var add in gamma) { idcDao.Insert(new Data.Entity.Migration.IDConversion("Author", add.DomesticID, add.ForeignID), _dataOpUnit.CurrentConnection); } //異ID x 異値:対象ライブラリのエンティティを変更せずそのままインポートする。 var delta = from a in anotherDbAuthors.Except(alpha).Except(beta).Except(gamma.Select(a => a.Author)) select a; foreach (var add in delta) { ImportAuthor(libManager, add); } }
public static IEnumerable <AuthorViewModel> OrderByNaturalString() { AuthorDao dao = new AuthorDao(); return(dao.FindAll().OrderBy(a => a.Name, new NaturalStringComparer()).ToViewModel()); }
public static IEnumerable <AuthorViewModel> FindAll() { AuthorDao dao = new AuthorDao(); return(dao.FindAll().ToViewModel()); }