Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Related entities as dto object #8

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Add related properties in SelectorExpression
  • Loading branch information
Gwenou committed Mar 21, 2017
commit 583197f508c32f0ddd3d18e723996314cbf256ae
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class CityDTO

public class CityMapper : MapperBase<City, CityDTO>
{
public override Expression<Func<Role, CityDTO>> CustomSelectorExpression
public Expression<Func<Role, CityDTO>> CustomSelectorExpression
{
get
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using DtoGenerator.TestSolution.DAL.Dto.Infrastructure;
using Safran.ProjectName1.Model;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Safran.ProjectName1.Business.DTO
{
public class SampleTable1DTO
{

////BCC/ BEGIN CUSTOM CODE SECTION
//Option : Generate linked objects and ID gettter
[Required]
public int SampleTable2Id { get { return SampleTable2 != null ? SampleTable2.Id : 0; } set { SampleTable2 = new SampleTable2DTO() { Id = value }; } }
public Nullable<int> SampleTable2_0_1Id { get { return SampleTable2_0_1?.Id; } set { SampleTable2_0_1 = (value == null) ? null : new SampleTable2DTO() { Id = value.Value }; } }
public ICollection<int> SampleTable3Ids { get { return SampleTable3?.Select(s => s.Id).ToList(); } set { SampleTable3 = value.Select(v => new SampleTable3DTO() { Id = v }).ToList(); } }

[Required]
public SampleTable2DTO SampleTable2 { get; set; }

public SampleTable2DTO SampleTable2_0_1 { get; set; }

public ICollection<SampleTable3DTO> SampleTable3 { get; set; }

int test = 3;

public int GetInt()
{
return test;
}
////ECC/ END CUSTOM CODE SECTION

[Required]
public int Id { get; set; }

[StringLength(10)]
[Required]
public string Title { get; set; }

[StringLength(200)]
[Required]
public string Description { get; set; }

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> Date { get; set; }

}

public class SampleTable1Mapper : MapperBase<SampleTable1, SampleTable1DTO>
{

////BCC/ BEGIN CUSTOM CODE SECTION
int test = 3;

public int GetInt()
{
return test;
}
////ECC/ END CUSTOM CODE SECTION
private SampleTable3Mapper _sampleTable3Mapper = new SampleTable3Mapper();

public override Expression<Func<SampleTable1, SampleTable1DTO>> SelectorExpression
{
get
{
return ((Expression<Func<SampleTable1, SampleTable1DTO>>)(p => new SampleTable1DTO()
{

////BCC/ BEGIN CUSTOM CODE SECTION
SampleTable2 = (p.SampleTable2 == null) ? null : new SampleTable2DTO() { Id = p.SampleTable2.Id, Title = p.SampleTable2.Title, Description = p.SampleTable2.Description },
SampleTable2_0_1 = (p.SampleTable2_0_1 == null) ? null : new SampleTable2DTO() { Id = p.SampleTable2_0_1.Id, Title = p.SampleTable2_0_1.Title, Description = p.SampleTable2_0_1.Description },
SampleTable3 = p.SampleTable3.Select(s => new SampleTable3DTO() { Id = s.Id, Title = s.Title, Description = s.Description, Value = s.Value }).ToList(),
////ECC/ END CUSTOM CODE SECTION
Id = p.Id,
Title = p.Title,
Description = p.Description,
Date = p.Date,
}));
}
}

public override void MapToModel(SampleTable1DTO dto, SampleTable1 model)
{

////BCC/ BEGIN CUSTOM CODE SECTION
//Option : Map linked object properties
if (dto.SampleTable2 != null) { model.SampleTable2 = new SampleTable2() { Id = dto.SampleTable2.Id, Title = dto.SampleTable2.Title, Description = dto.SampleTable2.Description }; }
if (dto.SampleTable2_0_1 != null) { model.SampleTable2_0_1 = new SampleTable2() { Id = dto.SampleTable2_0_1.Id, Title = dto.SampleTable2_0_1.Title, Description = dto.SampleTable2_0_1.Description }; }
if (dto.SampleTable3 != null) { model.SampleTable3 = dto.SampleTable3.Select(s => new SampleTable3() { Id = s.Id, Title = s.Title, Description = s.Description, Value = s.Value }).ToList(); }
////ECC/ END CUSTOM CODE SECTION
model.Id = dto.Id;
model.Title = dto.Title;
model.Description = dto.Description;
model.Date = dto.Date;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Safran.ProjectName1.Model;
using System.ComponentModel.DataAnnotations;
using DtoGenerator.TestSolution.DAL.Dto.Infrastructure;

namespace Safran.ProjectName1.Business.DTO
{
public class SampleTable2DTO
{
////BCC/ BEGIN CUSTOM CODE SECTION
////ECC/ END CUSTOM CODE SECTION

[Required]
public int Id { get; set; }

[StringLength(10)]
[Required]
public string Title { get; set; }

[StringLength(200)]
[Required]
public string Description { get; set; }
}

public class SampleTable2Mapper : MapperBase<SampleTable2, SampleTable2DTO>
{
////BCC/ BEGIN CUSTOM CODE SECTION
////ECC/ END CUSTOM CODE SECTION

public override Expression<Func<SampleTable2, SampleTable2DTO>> SelectorExpression
{
get
{
return ((Expression<Func<SampleTable2, SampleTable2DTO>>)(p => new SampleTable2DTO()
{
////BCC/ BEGIN CUSTOM CODE SECTION
////ECC/ END CUSTOM CODE SECTION
Id = p.Id,
Title = p.Title,
Description = p.Description,
}));
}
}

public override void MapToModel(SampleTable2DTO dto, SampleTable2 model)
{
////BCC/ BEGIN CUSTOM CODE SECTION
////ECC/ END CUSTOM CODE SECTION
model.Id = dto.Id;
model.Title = dto.Title;
model.Description = dto.Description;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Safran.ProjectName1.Model;
using System.ComponentModel.DataAnnotations;
using DtoGenerator.TestSolution.DAL.Dto.Infrastructure;

namespace Safran.ProjectName1.Business.DTO
{
public class SampleTable3DTO
{
////BCC/ BEGIN CUSTOM CODE SECTION
public ICollection<int> SampleTable1Ids { get { return SampleTable1?.Select(s => s.Id).ToList(); } set { SampleTable1 = value.Select(v => new SampleTable1DTO() { Id = v }).ToList(); } }
public ICollection<SampleTable1DTO> SampleTable1 { get; set; }
////ECC/ END CUSTOM CODE SECTION

[Required]
public int Id { get; set; }

[StringLength(50)]
[Required]
public string Title { get; set; }

[StringLength(200)]
[Required]
public string Description { get; set; }

[Required]
public short Value { get; set; }
}

public class SampleTable3Mapper : MapperBase<SampleTable3, SampleTable3DTO>
{
////BCC/ BEGIN CUSTOM CODE SECTION
////ECC/ END CUSTOM CODE SECTION

public override Expression<Func<SampleTable3, SampleTable3DTO>> SelectorExpression
{
get
{
return ((Expression<Func<SampleTable3, SampleTable3DTO>>)(p => new SampleTable3DTO()
{
////BCC/ BEGIN CUSTOM CODE SECTION
SampleTable1= p.SampleTable1.Select(s => new SampleTable1DTO() { Id = s.Id, Title = s.Title, Description = s.Description }).ToList(),
////ECC/ END CUSTOM CODE SECTION
Id = p.Id,
Title = p.Title,
Description = p.Description,
Value = p.Value,
}));
}
}

public override void MapToModel(SampleTable3DTO dto, SampleTable3 model)
{
////BCC/ BEGIN CUSTOM CODE SECTION
if (dto.SampleTable1 != null) { model.SampleTable1 = dto.SampleTable1.Select(s => new SampleTable1() { Id = s.Id, Title = s.Title, Description = s.Description}).ToList(); }
////ECC/ END CUSTOM CODE SECTION
model.Id = dto.Id;
model.Title = dto.Title;
model.Description = dto.Description;
model.Value = dto.Value;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -43,6 +44,9 @@
<Compile Include="Dto\CityDTO.cs" />
<Compile Include="Dto\ComputerDTO.cs" />
<Compile Include="Dto\RoleDTO.cs" />
<Compile Include="Dto\SampleTable1DTO.cs" />
<Compile Include="Dto\SampleTable2DTO.cs" />
<Compile Include="Dto\SampleTable3DTO.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@
<Compile Include="Entity\City.cs" />
<Compile Include="Entity\Person.cs" />
<Compile Include="Entity\PersonContact.cs" />
<Compile Include="Entity\EntityBase.cs" />
<Compile Include="Entity\Role.cs" />
<Compile Include="Entity\SampleTable1.cs" />
<Compile Include="Entity\SampleTable2.cs" />
<Compile Include="Entity\SampleTable3.cs" />
<Compile Include="Enumerations.cs" />
<Compile Include="Infrastructure\EntityBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace DtoGenerator.TestSolution.Model.Entity
{
public class City : EntityBase
{
public Guid UniqueId { get; set; }
public DateTime DateCreated { get; set; }
public string PostalCode { get; set; }

public string Name { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DtoGenerator.TestSolution.Model.Infrastructure;

namespace DtoGenerator.TestSolution.Model.Entity
{
public class EntityBase
{
public virtual int Id { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Safran.ProjectName1.Model
{
using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

public partial class SampleTable1
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public SampleTable1()
{
this.SampleTable3 = new HashSet<SampleTable3>();
}


[Required]
public int Id { get; set; }

[StringLength(10)]
[Required]
public string Title { get; set; }

[StringLength(200)]
[Required]
public string Description { get; set; }

[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public Nullable<System.DateTime> Date { get; set; }

[Required]
public virtual SampleTable2 SampleTable2 { get; set; }
public virtual SampleTable2 SampleTable2_0_1 { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SampleTable3> SampleTable3 { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace Safran.ProjectName1.Model
{
using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;

public partial class SampleTable2
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public SampleTable2()
{
this.SampleTable1 = new HashSet<SampleTable1>();
}


[Required]
public int Id { get; set; }

[StringLength(10)]
[Required]
public string Title { get; set; }

[StringLength(200)]
[Required]
public string Description { get; set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<SampleTable1> SampleTable1 { get; set; }
}
}
Loading