CANNOT IMPLICITLY CONVERT TYPE 'SYSTEM.GUID

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#
 2112  View(s)
Ratings:
Rate this:

I am getting the following error

Cannot implicitly convert type 'System.Guid?' to 'DataContracts.Market'

    private CellSite MapEntityToCellSitePOCO(t_CellSite _cellsite)

    {

        CellSite cellsite= new CellSite();

        cellsite.SiteId = _cellsite.SiteID;

        cellsite.Market.MarketID = _cellsite.MarketId;

        cellsite.Region.RegionId = _cellsite.RegionId;

       return cellsite;

    }

the following is my datacontracts file

    public class CellSite

{

    public Guid CellSiteID { get; set; }

    public string SiteId { get; set; }

    public Region Region { get; set; }

    public Market Market { get; set; }

    public Guid? ConstructionManager { get; set;}

   }

This is market.cs

      public class Market

{

    public Guid? MarketID { get; set; }

    public string OperatorMarketName { get; set; }

    public string MarketName { get; set; }

    public decimal AllOtherAmount { get; set; }

    public decimal RawLandAmount { get; set; }

    public decimal RenewalFee { get; set; }

    public bool IsActive { get; set; }

}

there is a column MarketId in cellsite table which i want to bring on.how can i do that? I am new to entity frame work. thanks in advance

  1. Sumit Kesarwani

    Post:378

    Points:2694
    Re: Cannot implicitly convert type 'System.Guid

    You have to initialize your Market and Region properties first:

    CellSite cellsite= new CellSite();

    cellsite.SiteId = _cellsite.SiteID;

    cellsite.Market = new Market();

    cellsite.Market.MarketID = _cellsite.MarketId;

    cellsite.Region = new Region();

    cellsite.Region.RegionId = _cellsite.RegionId;

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!