ОПРЕДЕЛЕНИЕ КЛАССА< /strong>
Код: Выделить всё
namespace Data.Entities
{
public class Computer
{
// COMPUTER BLOCK
public int id { get; set; }
public string name { get; set; }
public string serial { get; set; }
public string otherserial { get; set; }
public string uuid { get; set; }
public string comment { get; set; }
public Boolean? is_deleted { get; set; }
public IEnumerable SoftwareVersions { get; set; }
public virtual IEnumerable ComputerSoftwareVersions { get; set; }
}
Код: Выделить всё
namespace Data.Custom
{
public class CustomComputer
{
public int id { get; set; }
public string name { get; set; }
public string serial { get; set; }
public string uuid { get; set; }
public string comment { get; set; }
}
}
Код: Выделить всё
namespace Data.Entities
{
public class Software
{
public int id { get; set; }
public Boolean? is_deleted { get; set; }
public string name { get; set; }
public string comment { get; set; }
public DateTime? date_creation { get; set; }
//public int softwares_id { get; set; }
public int softwarecategories_id { get; set; }
public virtual SoftwareCategorie SoftwareCategorie { get; set; }
public int manufacturers_id { get; set; }
public virtual Manufacturer Manufacturer { get; set; }
public int entities_id { get; set; }
public virtual Entitie Entitie { get; set; }
public int groups_id { get; set; }
public virtual Group Group { get; set; }
public ICollection SoftwareVersions { get; set; }
}
}
Код: Выделить всё
namespace Data.Entities
{
public class SoftwareVersion
{
public int id { get; set; }
public string name { get; set; }
public int softwares_id { get; set; }
public virtual Software Software { get; set; }
public virtual ICollection Computers { get; set; }
public virtual ICollection ComputerSoftwareVersions { get; set; }
}
}
Код: Выделить всё
namespace Data.Custom
{
public class CustomSoftware
{
public int id { get; set; }
public string name { get; set; }
public string entity { get; set; }
public string publisher { get; set; }
public string group { get; set; }
public string software_category { get; set; }
public virtual IEnumerable versions { get; set; }
}
}
Код: Выделить всё
namespace Data.Custom
{
public class CustomSoftwareVersion
{
public string name { get; set; }
public IEnumerable installations { get; set; }
}
}
Код: Выделить всё
using System;
namespace Data.Custom
{
public class CustomComputerSoftwareVersion
{
public int id { get; set; }
public string name { get; set; }
public string status { get; set; }
public string hosting_area { get; set; }
}
}
Код: Выделить всё
public class ComputerMapping : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasMany(c => c.SoftwareVersions)
.WithMany(t => t.Computers)
.UsingEntity(x => x.HasOne(x => x.SoftwareVersion).WithMany().HasForeignKey(x => x.softwareversions_id).IsRequired(true),
x => x.HasOne(x => x.Computer).WithMany().HasForeignKey(x => x.items_id).IsRequired(true),
x => x.ToTable("glpi_items_softwareversions"));
builder.ToTable("computers");
}
}
}
Код: Выделить всё
{
public class SoftwareVersionMapping : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(c => c.id);
builder.HasOne(c => c.Software).WithMany(l => l.SoftwareVersions).HasForeignKey(c => c.softwares_id).IsRequired(false);
builder.HasMany(c => c.Computers)
.WithMany(t => t.SoftwareVersions)
.UsingEntity(x => x.HasOne(x => x.Computer).WithMany(l=>l.ComputerSoftwareVersions).HasForeignKey(x => x.items_id).IsRequired(true),
x => x.HasOne(x => x.SoftwareVersion).WithMany(l => l.ComputerSoftwareVersions).HasForeignKey(x => x.softwareversions_id).IsRequired(true),
x => x.ToTable("glpi_items_softwareversions"));
builder.ToTable("softwareversions");
}
}
}
Код: Выделить всё
{
public class ComputerSoftwareVersionMapping : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.HasKey(c => c.id);
builder.HasOne(c => c.SoftwareVersion).WithMany(l => l.ComputerSoftwareVersions).HasForeignKey(c => c.softwareversions_id).IsRequired(true);
builder.HasOne(c => c.Computer).WithMany(l => l.ComputerSoftwareVersions).HasForeignKey(c => c.items_id).IsRequired(false);
builder.ToTable("items_softwareversions");
}
}
}
Код: Выделить всё
public IQueryable GetById(int id)
{
return _db
.Where(s => s.id == id)
.Where(s => s.is_deleted == false)
.Include(s => s.SoftwareVersions)
.ThenInclude(d => d.Computers)
.ThenInclude(x => x.ComputerWsusInfo)
.ThenInclude(c => c.ComputerDetailDatacenter)
.Select(s => new CustomSoftware
{
id = s.id,
name = s.name,
entity = s.Entitie.name,
publisher = s.Manufacturer.name,
group = s.Group.name,
software_category = s.SoftwareCategorie.completename,
versions = s.SoftwareVersions.Select(d => new CustomSoftwareVersion
{
name = d.name,
installations = d.Computers.Select(x => new CustomComputerSoftwareVersion
{
name = x.name,
status = x.State.name,
hosting_area = x.ComputerWsusInfo.ComputerDetailDatacenter.name
})
})
});
}
Спасибо, что уделили время!
С уважением!
Подробнее здесь: https://stackoverflow.com/questions/792 ... ng-in-json
Мобильная версия