OK, there are differences in
Repository.GetProjects((Guid)TempData["userid"]);
Old code that works
Code: Select all
public IQueryable<Project> GetProjects(Guid UserId)
{
var query = from p in _context.Projects
where p.ParentProjectId == null
from up in _context.UserProjects
where up.UserId == UserId && up.ProjectId == p.Id
select p;
return query;
}
with this result query:
Code: Select all
{SELECT
[Extent1].[Id] AS [Id],
[Extent1].[Title] AS [Title],
[Extent1].[Number] AS [Number],
[Extent1].[Description] AS [Description],
[Extent1].[Created] AS [Created],
[Extent1].[Image] AS [Image],
[Extent1].[ParentProjectId] AS [ParentProjectId],
[Extent1].[RowVersion] AS [RowVersion]
FROM [dbo].[Projects] AS [Extent1]
INNER JOIN [dbo].[UserProjects] AS [Extent2] ON [Extent2].[ProjectId] = [Extent1].[Id]
WHERE ([Extent1].[ParentProjectId] IS NULL) AND ([Extent2].[UserId] = @p__linq__0)}
This is the old project entity:
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace BIMcube.DataAccess
{
public class Project: BaseEntity
{
[Key]
public Guid Id { get; set; }
public string Title { get; set; }
public string Number { get; set; }
public string Description { get; set; }
public DateTime Created { get; set; }
public string Image { get; set; }
public Guid? ParentProjectId { get; set; }
[ForeignKey("ParentProjectId")]
public virtual ICollection<Project> SubProjects { get; set; }
public virtual ICollection<ProjectAttribute> ProjectAttributes { get; set; }
public virtual ICollection<ProjectContact> ProjectContacts { get; set; }
}
}
This is the old report dictionary section:
Code: Select all
<Dictionary Ref="1" type="Dictionary" isKey="true">
<BusinessObjects isList="true" count="0" />
<Databases isList="true" count="0" />
<DataSources isList="true" count="1">
<Project Ref="2" type="Stimulsoft.Report.Dictionary.StiBusinessObjectSource" isKey="true">
<Alias>Project</Alias>
<Columns isList="true" count="8">
<value>Created,System.DateTime</value>
<value>Description,System.String</value>
<value>Id,System.Guid</value>
<value>Image,System.String</value>
<value>Number,System.String</value>
<value>ParentProjectId,System.Nullable`1[System.Guid]</value>
<value>RowVersion,System.Byte[]</value>
<value>Title,System.String</value>
</Columns>
<Dictionary isRef="1" />
<IsCloud>False</IsCloud>
<Name>Project</Name>
<NameInSource>Project</NameInSource>
</Project>
</DataSources>
<Relations isList="true" count="0" />
<Report isRef="0" />
<Variables isList="true" count="0" />
</Dictionary>
This is the new code that also works but RegData takes too long.
Code: Select all
public IQueryable<Project> GetProjects(Guid UserId)
{
var revisions = _context.ProjectRevisions.Where(r => r.Identifier == UserId && r.Parent == null && r.Action == RevisionAction.Created).Include("Childs");
var result = new List<Project>();
foreach (var rev in revisions)
{
if (rev.Childs.First().Action != RevisionAction.Deleted)
{
var project = _context.Projects.Find(rev.Childs.First().DataId);
result.Add(project);
}
}
return result.AsQueryable();
}
The new result query:
Code: Select all
{System.Collections.Generic.List`1[BIMcube.DomainModels.Project]}
The new project entity:
Code: Select all
using BIMcube.DataAccess;
using BIMcube.DomainModels.Revision;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BIMcube.DomainModels
{
public class Project : BaseEntity, IRevision
{
public Project()
{
Id = Guid.NewGuid();
Projects = new List<Project>();
Created = DateTime.Now;
ProjectContacts = new List<ProjectContact>();
ProjectAttributes = new List<ProjectAttribute>();
}
public Project(Project Parent)
: this()
{
this.Parent = Parent;
Parent.Projects.Add(this);
}
public Guid Id { get; set; }
public Project Parent { get; set; }
public string Title { get; set; }
public string Number { get; set; }
public string Description { get; set; }
public DateTime Created { get; set; }
public virtual ICollection<Project> Projects { get; set; }
public Guid UserId { get; set; }
public bool Deleted { get; set; }
public virtual ICollection<ProjectAttribute> ProjectAttributes { get; set; }
public virtual ICollection<ProjectContact> ProjectContacts { get; set; }
public ICollection<IRevision> GetChilds()
{
return new List<IRevision>(Projects);
}
public IRevision GetParent()
{
return Parent;
}
public void SetParent(IRevision Parent)
{
this.Parent = (Project)Parent;
}
public IRevision Clone()
{
var prj = new Project();
prj.Id = Id;
foreach (var p in Projects)
{
prj.Projects.Add(p);
}
foreach (var p in ProjectContacts)
{
prj.ProjectContacts.Add(p);
}
foreach (var p in ProjectAttributes)
{
prj.ProjectAttributes.Add(p);
}
prj.Parent = Parent;
prj.Created = Created;
prj.Description = Description;
prj.Number = Number;
prj.Title = Title;
prj.Deleted = Deleted;
prj.UserId = UserId;
return prj;
}
public void ExchangeChilds(IRevision Add, IRevision Remove)
{
var list = Projects.ToList();
int index = list.IndexOf((Project)Remove);
list.Remove((Project)Remove);
if (Add != null)
{
list.Insert(index, (Project)Add);
}
Projects = list;
}
public Guid GetIdentifier()
{
return UserId;
}
public void SetIdentifier(Guid Identifier)
{
UserId = Identifier;
}
}
}
This is the new dictionary section in report:
Code: Select all
<Dictionary Ref="1" type="Dictionary" isKey="true">
<BusinessObjects isList="true" count="0" />
<Databases isList="true" count="0" />
<DataSources isList="true" count="1">
<Project Ref="2" type="Stimulsoft.Report.Dictionary.StiBusinessObjectSource" isKey="true">
<Alias>Project</Alias>
<Columns isList="true" count="5">
<value>Created,System.DateTime</value>
<value>Description,System.String</value>
<value>Id,System.Guid</value>
<value>Number,System.String</value>
<value>Title,System.String</value>
</Columns>
<Dictionary isRef="1" />
<IsCloud>False</IsCloud>
<Name>Project</Name>
<NameInSource>Project</NameInSource>
</Project>
</DataSources>
<Relations isList="true" count="0" />
<Report isRef="0" />
<Variables isList="true" count="0" />
</Dictionary>
Perhaps you have an idea why RegData now has a problem with that?
But the report result is correct in both cases!