Ejemplo n.º 1
0
        /// <summary>
        /// использовалась для тестов, пока не нужна
        /// </summary>
        /// <param name="sWord"></param>
        /// <param name="sChild"></param>
        public void UpdateRelation(string sWord, string sChild)
        {
            var wordId = from p in m_Database.tbl_WordItems
                         where p.Word == sWord
                         select new
            {
                Id = p.Id
            };

            var childId = from p in m_Database.tbl_WordItems
                          where p.Word == sWord
                          select new
            {
                Id = p.Id
            };

            var rel = from p in m_Database.tbl_RelationItems
                      where p.ChildId == childId.First().Id&& p.ParentId == wordId.First().Id
                      select p;

            if (rel.Count() > 0)
            {
                rel.First().RelationType = 1;
            }
            else
            {
                RelationItem aRelation = RelationItem.CreateRelationItem(1, 2, true, (short)RelationType.Normal, 0);
                m_Database.AddTotbl_RelationItems(aRelation);
            }

            m_Database.SaveChanges();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// проверяет есть ли сущность "связь" и добавляет ее в БД если отсутствует
        /// </summary>
        /// <param name="sParent">слово-родитель</param>
        /// <param name="sChild">слово-потомок</param>
        /// <param name="relType">тип отношения</param>
        /// <param name="relGroupId">номер группы отношения.
        /// Этот номер используется для определения исходной формы слова, т.к. словарь словоформ может содержать несколько исходных значений</param>
        /// <returns>созданную сущность "связь"</returns>
        public RelationItem AddRelation(string sParent, string sChild, RelationType relType, short?relGroupId)
        {
            int nParentId = GetWordId(sParent);

            if (nParentId < 0)
            {
                nParentId = AddWord(sParent, true).Id;
            }

            int nChildId = GetWordId(sChild);

            if (nChildId < 0)
            {
                nChildId = AddWord(sChild, true).Id;
            }

            RelationItem anItem = GetRelationItem(nParentId, nChildId);

            if (anItem == null)
            {
                anItem = RelationItem.CreateRelationItem(nParentId, nChildId, true, (short)relType, 0);
                anItem.RelationTypeGroup = relGroupId;

                m_Database.AddTotbl_RelationItems(anItem);
                m_Database.SaveChanges();
            }

            return(anItem);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new RelationItem object.
        /// </summary>
        /// <param name="parentId">Initial value of the ParentId property.</param>
        /// <param name="childId">Initial value of the ChildId property.</param>
        /// <param name="isAuto">Initial value of the IsAuto property.</param>
        /// <param name="relationType">Initial value of the RelationType property.</param>
        /// <param name="id">Initial value of the Id property.</param>
        public static RelationItem CreateRelationItem(global::System.Int32 parentId, global::System.Int32 childId, global::System.Boolean isAuto, global::System.Int16 relationType, global::System.Int32 id)
        {
            RelationItem relationItem = new RelationItem();

            relationItem.ParentId     = parentId;
            relationItem.ChildId      = childId;
            relationItem.IsAuto       = isAuto;
            relationItem.RelationType = relationType;
            relationItem.Id           = id;
            return(relationItem);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// сохраняет измененную сущность "связь" в БД
        /// </summary>
        /// <param name="anItem">сущность связь, которую надо сохранить</param>
        public void UpdateRelation(RelationItem anItem)
        {
            var rel = from relation in m_Database.tbl_RelationItems
                      where anItem.Id == relation.Id
                      select relation;

            if (rel.Count() > 0)
            {
                rel.First().RelationType = anItem.RelationType;
                m_Database.SaveChanges();
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the tbl_RelationItems EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddTotbl_RelationItems(RelationItem relationItem)
 {
     base.AddObject("tbl_RelationItems", relationItem);
 }