ExternalEntityLinkServerFunctions.cs 1.17 KB
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Domain.SessionExtensions;
using Sungero.Domain.Shared;
using DirRX.LongTermArchive.ExternalEntityLink;

namespace DirRX.LongTermArchive.Server
{
  partial class ExternalEntityLinkFunctions
  {
    /// <summary>
    /// Получить все экземпляры сущностей указанного типа.
    /// </summary>
    /// <returns>Список записей текущей сущности.</returns>
    [Remote]
    public IQueryable<IEntity> GetEntities()
    {
      IQueryable<IEntity> entities = null;
      
      if (!string.IsNullOrWhiteSpace(_obj.EntityType))
      {
        try
        {
          using (var session = new Sungero.Domain.Session())
          {
            entities = session.GetAll(Sungero.Domain.Shared.TypeExtension.GetTypeByGuid(Guid.Parse(_obj.EntityType)));
          }
        }
        catch (Exception e)
        {
          Logger.DebugFormat("Ошибка получения элементов сущности по ее типу: {0}", e.Message);
        }
      }
      
      return entities;
    }
  }
}