at first I want to make my apologize for my english
I've a problem with DTOs, I'm using SQLAzure for my DB and I host services on Azure
Some of my objects have ICollection of other objects, typically a country(Country Table) has a collection of airports (Airport Table), I use Entity Framework for DB Connection and DTO for present my object
A this point everything fine but on the client side when I want to use the property Icollection of an object, VS says "ambiguous name", it seems during the serialization it re-type my object
I've DTOAirport on server side
I've two sorts of airport on client side after serialization first the airportservice.airportClient.DTOAirport second the countryService.countryClient.DTOAirport
I can't use my classic DTOAirport and it dont support cast...
I've a lot of problems whith it, that I don't have on "classics WCF services"
I can post code if you want it
Thanks a lot for reading me
{
[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; }
}
}
Here are my DTOs, I use a mapper for map it on Entity Framework classes
this is a typical service on server side
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;
}
}
here is a Console test on client side and the errors it gaves me
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
If you need something else
In this exemple exemple I test whith DTOs on Client side, the result was same, it seems the service re-type the objects
Maybe it is the proxy but it not mades a long time I work on azure a开发者_StackOverflownd .NET in general
Your error message has a path which includes ".oldversions".
Is there a chance that the client and server are two different versions?
Also I see that you have a nullable int, sometimes nullable types can be a problem. You could try it without this field just in case.
精彩评论