我正在使用带有 asp.net core 3.1 的 GraphQL.NET 来开发基于 graphql 的 api。我有以下代码:
联系DTO.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; }
}
}
地址DTO.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 的方法。
谁能帮助我以更好的方式进行此映射