public void addTaxonNames(IEnumerable<TaxonName> taxa, TaxonList list) { if (!TaxonList.ValidTableIDs.Contains(list.TableID)) throw new ArgumentException("list"); using (var taxctx = new TaxonDataContext(list.TableID)) { taxctx.TaxonNames.InsertAllOnSubmit(taxa); try { taxctx.SubmitChanges(); } catch (Exception) { System.Diagnostics.Debugger.Break(); //TODO Log } } }
private void withTaxonTable(int id, Action<TaxonDataContext> operation) { using (var ctx = new TaxonDataContext(id)) { operation(ctx); } }
private IEnumerable<TaxonName> getTaxonNames(int tableID, string query) { var queryWords = (from word in query.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) select word).ToArray(); using (var ctx = new TaxonDataContext(tableID)) { var q = ctx.TaxonNames as IQueryable<TaxonName>; //Match Genus if (queryWords.Length > 0 && queryWords[0] != WILDCARD) { q = from tn in q where tn.GenusOrSupragenic.StartsWith(queryWords[0]) select tn; } //Match SpeciesEpithet if (queryWords.Length > 1 && queryWords[1] != WILDCARD) { q = from tn in q where tn.SpeciesEpithet.StartsWith(queryWords[1]) select tn; } //Match Infra if (queryWords.Length > 2 && queryWords[2] != WILDCARD) { q = from tn in q where tn.InfraspecificEpithet.StartsWith(queryWords[2]) select tn; } //Order q = from inf in q orderby inf.GenusOrSupragenic, inf.SpeciesEpithet, inf.InfraspecificEpithet select inf; // Treating the query as an enumerable prevents the following operators // from being applied on the DB // which is necessary, because "Contains" is not supported in SQL CE // instead, it is evaluated in application code var e = q.AsEnumerable(); if (queryWords.Length > 3) { e = from inf in e where queryWords.Skip(3).Where(w => w != WILDCARD).All(word => inf.TaxonNameCache.Contains(word)) select inf; } foreach (var item in e) { yield return item; } } }