private static IQueryable <ProteinSearchValue> GetNameSearchValues(this FaToolDbEntities entities)
 {
     return(entities
            .GetProteinNameValues()
            .Union(entities.GetSynonymValues())
            .Union(entities.GetTranscriptIDValues()));
 }
        public static TEntity Init <TEntity, TKey>(this FaToolDbEntities ctx, TKey id)
            where TEntity : class, IEntity <TKey>
        {
            var entity = ctx.Create <TEntity>();

            entity.ID         = id;
            entity.RowVersion = new byte[8];
            return(entity);
        }
 public static IQueryable <ProteinSearchValue> GetProteinSearchValues(
     this FaToolDbEntities entities,
     ProteinSearchOption option,
     string organismId)
 {
     return(from p in entities.GetSourceProteins()
            join pv in entities.GetProteinSearchValues(option) on p.ProteinID equals pv.ProteinID
            where p.SourceOrganismID == organismId
            select pv);
 }
        private static IQueryable <SourceProtein> GetSourceProteins(this FaToolDbEntities entities)
        {
            var query = from gm in entities.GeneModels
                        select new SourceProtein()
            {
                SourceOrganismID = gm.GeneModelSource.Organism.ID,
                ProteinID        = gm.Protein.ID
            };

            return(query.Distinct());
        }
 private static IQueryable <ProteinSearchValue> GetProteinNameValues(this FaToolDbEntities entities)
 {
     return(from p in entities.Proteins
            select new ProteinSearchValue()
     {
         ProteinID = p.ID,
         ProteinName = p.Name,
         TermID = null,
         TermName = null,
         OntologyID = null,
         OntologyName = null,
         Value = p.Name
     });
 }
 private static IQueryable <ProteinSearchValue> GetTranscriptIDValues(this FaToolDbEntities entities)
 {
     return(from gm in entities.GeneModels
            select new ProteinSearchValue()
     {
         ProteinID = gm.Protein.ID,
         ProteinName = gm.Protein.Name,
         TermID = null,
         TermName = null,
         OntologyID = null,
         OntologyName = null,
         Value = gm.TranscriptID
     });
 }
 private static IQueryable <ProteinSearchValue> GetDescriptionValues(this FaToolDbEntities entities)
 {
     return(from param in entities.ProteinParams
            select new ProteinSearchValue()
     {
         ProteinID = param.ParamContainer.ID,
         ProteinName = param.ParamContainer.Name,
         TermID = param.Term.ID,
         TermName = param.Term.Name,
         OntologyID = param.Term.Ontology.ID,
         OntologyName = param.Term.Ontology.Name,
         Value = param.Value
     });
 }
 private static IQueryable <ProteinSearchValue> GetSynonymValues(this FaToolDbEntities entities)
 {
     return(from s in entities.Synonyms
            select new ProteinSearchValue()
     {
         ProteinID = s.Protein.ID,
         ProteinName = s.Protein.Name,
         TermID = s.SynonymType.ID,
         TermName = s.SynonymType.Name,
         OntologyID = s.SynonymType.Ontology.ID,
         OntologyName = s.SynonymType.Ontology.Name,
         Value = s.SynonymValue
     });
 }
 private static IQueryable <ProteinSearchValue> GetFunctionValues(this FaToolDbEntities entities)
 {
     return(from a in entities.Annotations
            select new ProteinSearchValue()
     {
         ProteinID = a.Protein.ID,
         ProteinName = a.Protein.Name,
         TermID = a.Term.ID,
         TermName = a.Term.Name,
         OntologyID = a.Term.Ontology.ID,
         OntologyName = a.Term.Ontology.Name,
         Value = a.Term.Name
     });
 }
        public static IQueryable <ProteinSearchValue> GetProteinSearchValues(
            this FaToolDbEntities entities,
            ProteinSearchOption option)
        {
            switch (option)
            {
            case ProteinSearchOption.Function:
                return(GetFunctionValues(entities));

            case ProteinSearchOption.Description:
                return(GetDescriptionValues(entities));

            default:
                return(GetNameSearchValues(entities));
            }
        }
        public static Task LoadCollection <TEntity, TElement>(
            this FaToolDbEntities ctx,
            TEntity entity,
            Expression <Func <TEntity, ICollection <TElement> > > navigationProperty,
            params string[] includes)
            where TEntity : class, IEntity
            where TElement : class, IEntity
        {
            var query = ctx
                        .Entry(entity)
                        .Collection(navigationProperty)
                        .Query();

            foreach (var include in includes)
            {
                query = query.Include(include);
            }

            return(query.LoadAsync());
        }
 public static TEntity Create <TEntity>(this FaToolDbEntities ctx)
     where TEntity : class, IEntity
 {
     return(ctx.Core.CreateObject <TEntity>());
 }
 public static Task <TEntity> Find <TEntity>(this FaToolDbEntities ctx, object id)
     where TEntity : class, IEntity
 {
     return(ctx.Set <TEntity>().FindAsync(id));
 }
 public static async Task <bool> Exists <TEntity>(this FaToolDbEntities ctx, string id)
     where TEntity : class, IEntity <string>
 {
     return(await ctx.Exists <TEntity>(x => x.ID == id));
 }
 public static async Task <bool> Exists <TEntity>(this FaToolDbEntities ctx, Expression <Func <TEntity, bool> > predicate)
     where TEntity : class, IEntity
 {
     return(await ctx.Set <TEntity>().AnyAsync(predicate));
 }