Unknown CS1003 Error

无人久伴 提交于 2020-06-27 18:38:27

问题


I can't compile my project for code-first migrations in entity framework past a certain point. I am reading in values from xml to populate a table. I have the following code:

        //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();

I am getting the following error in the output window: Configuration.cs(179,71,179,80): error CS1003: Syntax error, ',' expected but I am not receiving any errors in the error list and I cannot for the life of me see a missing ,.

The xml is as follows:

<?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>

Could someone please tell me either: a) where the missing comma is, or b) what the real issue leading me to get this error is.

Thanks.


回答1:


The error is on this line:

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

And you get it because of the var keyword. You must remove it. It's not clear why you have it there, but if you are trying to declare the variable, then do it on a previous line:

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

Having said that, if you wait a while, C# version 7 will actually support this (though it's unclear if you can use var instead of an explicit type just yet). Take a look here for the proposed features: https://blogs.msdn.microsoft.com/dotnet/2016/08/24/whats-new-in-csharp-7-0/



来源:https://stackoverflow.com/questions/41373260/unknown-cs1003-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!