2016-12-29 85 views
0

我無法編譯我的項目,以便在實體框架中的代碼優先遷移超過特定點。我正在讀取xml中的值來填充表格。我有以下代碼:未知CS1003錯誤

 //EnrolmentProgramStartDate 

     var programQuery = from r in context.EnrolmentPrograms 
          select r; 

     var programList = programQuery.ToList<Entities.MetaData.Enrolment.EnrolmentProgram>(); 

     resourceName = "LearnLogicElicos_WebApi.SeedData.MetaData.Enrolment.enrolment_program_start_date.xml"; 
     stream = assembly.GetManifestResourceStream(resourceName); 
     xml = XDocument.Load(stream); 
     List<Entities.MetaData.Enrolment.EnrolmentProgramStartDate> enrolmentStartdates = new List<Entities.MetaData.Enrolment.EnrolmentProgramStartDate>(); 

     foreach (var e in xml.Root.Elements("StartDate")) 
     { 
      DateTime.TryParse((string)e.Element("Start"), out var startDate); 

      enrolmentStartdates.Add(new Entities.MetaData.Enrolment.EnrolmentProgramStartDate() 
      { 
       PrgmCode = (string)e.Element("ProgramCode"), 
       StartDate = startDate 
      }); 
     } 

     var programStartdateWithFk = (from t1 in enrolmentStartdates 
             join t2 in programList 
             on t1.PrgmCode equals t2.PrgmCode 
             select new Entities.MetaData.Enrolment.EnrolmentProgramStartDate 
             { 
              PrgmCode = t1.PrgmCode, 
              StartDate = t1.StartDate, 
              EnrolmentProgramFk = t2.PrgmPk 
             }); 

     context.EnrolmentProgramStartDates.AddRange(programStartdateWithFk); 

     context.SaveChanges(); 

我收到以下錯誤在輸出窗口:Configuration.cs(179,71,179,80): error CS1003: Syntax error, ',' expected,但我不是在錯誤列表中收到任何錯誤,我不能爲我的生活中看到失蹤,

的XML如下:

<?xml version="1.0" encoding="utf-8" ?> 
<Starts> 
    <StartDate> 
    <ProgramCode>DEC25</ProgramCode> 
    <Start>2018,1,2</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>DEC15</ProgramCode> 
    <Start>2018,3,19</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>DEC10</ProgramCode> 
    <Start>2018,4,30</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>DEC5W</ProgramCode> 
    <Start>2018,6,4</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>DEC5R</ProgramCode> 
    <Start>2018,6,4</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>DEC5S</ProgramCode> 
    <Start>2018,6,4</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>DEC5L</ProgramCode> 
    <Start>2018,6,4</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>GE</ProgramCode> 
    <Start>2018,1,2</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>GE</ProgramCode> 
    <Start>2018,1,8</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>GE</ProgramCode> 
    <Start>2018,1,15</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>GE</ProgramCode> 
    <Start>2018,1,22</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>GE</ProgramCode> 
    <Start>2018,1,29</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>GE</ProgramCode> 
    <Start>2018,2,5</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>ITP</ProgramCode> 
    <Start>2018,1,2</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>ITP</ProgramCode> 
    <Start>2018,1,8</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>ITP</ProgramCode> 
    <Start>2018,1,15</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>ITP</ProgramCode> 
    <Start>2018,1,22</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>ITP</ProgramCode> 
    <Start>2018,1,29</Start> 
    </StartDate> 
    <StartDate> 
    <ProgramCode>ITP</ProgramCode> 
    <Start>2018,2,5</Start> 
    </StartDate> 
</Starts> 

可能有人請告訴我是:a)在缺少逗號,或b)什麼導致我得到這個錯誤,真正的問題是。

謝謝。

+1

你是對的 - 壞標題。我改變了它試圖更好地反映我的問題。 – Ben

回答

3

的錯誤是在這條線:

DateTime.TryParse((string)e.Element("Start"), out var startDate); 

,你會得到它,因爲var關鍵字。你必須刪除它。目前尚不清楚爲什麼你有它在那裏,但如果你想聲明變量,然後再去做一個上一行:

DateTime startDate; 
DateTime.TryParse((string)e.Element("Start"), out startDate); 

說了這麼多,如果你等一會兒,C#版本7將實際的支持這(儘管目前還不清楚你是否可以使用var而不是明確的類型)。在這裏看看建議的功能:https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/