起初我想为我的英语道歉
我遇到了DTO问题,我正在使用SQLAzure作为我的数据库而我在Azure上托管服务
我的一些对象有ICollection的其他对象,通常是一个国家(Country Table)有一组机场(Airport Table),我使用Entity Framework for DB Connection和DTO来呈现我的对象
这一点一切都很好,但在客户端,当我想使用对象的属性Icollection,VS说“模糊名称”时,似乎在序列化期间它重新输入我的对象
我在服务器端有DTOAirport
序列化后我在客户端有两种类型的机场 首先是airportservice.airportClient.DTOAirport 第二个是countryService.countryClient.DTOAirport
我不能使用我的经典DTOAirport而且它不支持演员......
我有很多问题,我没有“经典WCF服务”
如果你愿意,我可以发布代码
非常感谢您阅读我
{
[DataContract]
public class DTOAirport
{
[DataMember]
public int IdAirportDTO { get; set; }
[DataMember]
public string NameAirportDTO { get; set; }
[DataMember]
public string IATACodeDTO { get; set; }
[DataMember]
public string ICAOCodeDTO { get; set; }
[DataMember]
public string ZoneDTO { get; set; }
[DataMember]
public int FKCountryDTO { get; set; }
[DataMember]
public string CityDTO { get; set; }
[DataMember]
public double LatitudeDTO { get; set; }
[DataMember]
public double LongitudeDTO { get; set; }
[DataMember]
public Nullable<int> AltitudeDTO { get; set; }
}
}
{
[DataContract]
public class DTOCountry
{
[DataMember]
public int IdCountryDTO { get; set; }
[DataMember]
public string NameCountryDTO { get; set; }
[DataMember]
public ICollection<DTOAirport> AirportsListDTO { get; set; }
}
}
以下是我的DTO,我使用mapper将它映射到Entity Framework类
这是服务器端的典型服务
public DTOAirport GetAirportById(int idAirport)
{
using (FlexAzureContainer1 context = new FlexAzureContainer1())
{
DTOAirport airport = new DTOAirport();
airport = DTOAirportMapper.MapFrom(context.DM_AIRPORTS.Where(a => a.IdAirport == idAirport).FirstOrDefault());
return airport;
}
}
public DTOCountry GetCountryById(int idCountry)
{
using (FlexAzureContainer1 context = new FlexAzureContainer1())
{
DTOCountry country = new DTOCountry();
country = DTOCountryMapper.MapFrom(context.DM_COUNTRIES.Where(c => c.IdCountry == idCountry).FirstOrDefault());
return country;
}
}
这是客户端的控制台测试以及它给我带来的错误
public class Program
{
static AirportService.AirportServiceClient myAirportService = new AirportService.AirportServiceClient();
static CountryService.CountryServiceClient myCountryService = new CountryService.CountryServiceClient();
public static void Main(string[] args)
{
List<DTOAirport>airportsList = myCountryService.GetCountryById(1).AirportsListDTO.ToList();
DTOCountry country = myCountryService.GetCountryById(1);
DTOAirport airport = myAirportService.GetAirportById(1);
foreach (DTOAirport airport2 in country.AirportsListDTO.ToList())
{
Console.WriteLine(airport2.NameAirportDTO);
}
Console.WriteLine(country.NameCountryDTO);
Console.WriteLine(airport.NameAirportDTO);
Console.ReadLine();
}
}
}
Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<FlexinergieAircraft.Client.CountryService.DTOAirport>' to 'System.Collections.Generic.List<FlexinergieAircraft.Client.DTOAirport>' D:\Projects\FlexinergieAicraft.OldVersions\FlexinergieAircraft17\FlexinergieAircraft\FlexinergieAircraft.Client\FlexinergieAircraft.Client\Program.cs 17 45 FlexinergieAircraft.Client
Error 2 Cannot implicitly convert type 'FlexinergieAircraft.Client.CountryService.DTOCountry' to 'FlexinergieAircraft.Client.DTOCountry' D:\Projects\FlexinergieAicraft.OldVersions\FlexinergieAircraft17\FlexinergieAircraft\FlexinergieAircraft.Client\FlexinergieAircraft.Client\Program.cs 18 34 FlexinergieAircraft.Client
Error 3 Cannot implicitly convert type 'FlexinergieAircraft.Client.AirportService.DTOAirport' to 'FlexinergieAircraft.Client.DTOAirport' D:\Projects\FlexinergieAicraft.OldVersions\FlexinergieAircraft17\FlexinergieAircraft\FlexinergieAircraft.Client\FlexinergieAircraft.Client\Program.cs 19 34 FlexinergieAircraft.Client
如果您还需要其他东西
在这个例子中我在客户端测试了DTO,结果是一样的,似乎服务重新输入了对象
也许它是代理,但是我在很长一段时间内一直在研究azure和.NET
答案 0 :(得分:1)
您的错误消息的路径包含&#34; .oldversions&#34;。
客户端和服务器是否有两种不同的版本?
另外我看到你有一个可以为空的int,有时可以为空的类型可能是个问题。为了以防万一,您可以在没有此字段的情况下尝试。