Как эффективно отобразить все свойства класса DTO в класс FiledType, используя GraphQL. NET? - PullRequest
0 голосов
/ 03 марта 2020

Я использую GraphQL. NET с asp. net core 3.1 для разработки apis на основе graphql. У меня есть следующий код:

ContactDTO.cs

    public class ContactDTO
    {
        public int ContactId { get; set; }

        public int? ImageId { get; set; }

        public string ImagePath { get; set; }

        public string OfficePhone { get; set; }

        public string OfficeFaxNumber { get; set; }

        public string MobilePhoneNumber { get; set; }

        public string Email { get; set; }

        public string Website { get; set; }

        public string FaceBookUrl { get; set; }

        public string TwitterUrl { get; set; }

        public string LinkedInUrl { get; set; }

        public string GooglePlusUrl { get; set; }

        public string WeChatUrl { get; set; }

        public string WeboUrl { get; set; }

        public string XINGUrl { get; set; }

        public string VKUrl { get; set; }

        public int? CountryId { get; set; }

        public string CreatedDate { get; set; }

        public string UpdatedDate { get; set; }

        public string EmpGUID { get; set; }

        public int? LanguageId { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string NativeName { get; set; }

        public string Title { get; set; }

        public string Role { get; set; }

        public string EmployeeLevel { get; set; }

        public string Introduction { get; set; }

        public string Organization { get; set; }

        public string OrganizationUnitName { get; set; }

        public int AddressId { get; set; }

        public AddressDTO address { get; set; }
    }
}

AddressDTO.cs

public class AddressDTO
{
    public int AddressId { get; set; }

    public string Street { get; set; }

    public string Country { get; set; }

    public string City { get; set; }
}

ContactType.cs

public class ContactType : ObjectGraphType<ContactDTO>, IGraphQLType
{
    public ContactType()
    {
        Name = "Contact";
        Field(co => co.ContactId, nullable: true);
        Field(co => co.OfficePhone, nullable: true);
        Field(co => co.OfficeFaxNumber, nullable: true);
        Field(co => co.MobilePhoneNumber, nullable: true);
        Field(co => co.Email, nullable: true);
        Field(co => co.Website, nullable: true);
        Field(co => co.FaceBookUrl, nullable: true);
        Field(co => co.TwitterUrl, nullable: true);
        Field(co => co.LinkedInUrl, nullable: true);
        Field(co => co.GooglePlusUrl, nullable: true);
        Field(co => co.WeChatUrl, nullable: true);
        Field(co => co.WeboUrl, nullable: true);
        Field(co => co.XINGUrl, nullable: true);
        Field(co => co.VKUrl, nullable: true);
        Field(co => co.FirstName, nullable: true);
        Field(co => co.LastName, nullable: true);
        Field(co => co.NativeName, nullable: true);
        Field(co => co.Title, nullable: true);
        Field(co => co.Role, nullable: true);
        Field(co => co.EmployeeLevel, nullable: true);
        Field(co => co.Introduction, nullable: true);
        Field(co => co.Organization, nullable: true);
        Field(co => co.OrganizationUnitName, nullable: true);
        Field(co => co.ImagePath, nullable: true);
        Field<AddressType>(
            "address",
            resolve: context =>
            {
                return context.Source.address;
            }
        );
    }
}

В приведенном выше примере ContactType.cs - это очень обширный класс со многими свойствами, которые унаследованы от ContactDTO.cs.

Я ищу способ сопоставить все свойства ContactDTO.cs с ContactType.cs.

Может кто-нибудь помочь мне сделать это отображение лучше

...