1

我收到以下错误

无法隐式转换类型“System.Guid?” 到“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;
    }

以下是我的数据合同文件


    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;}
   }

这是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; }
}

我想在 cellsite 表中有一个 MarketId 列。我该怎么做?我是实体框架工作的新手。提前致谢

4

1 回答 1

0

您必须首先初始化您的MarketRegion属性:

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;
于 2013-04-01T20:36:04.523 回答