LINQ - Linq to XmL - Asked By Donnie Talley on 24-Jan-12 03:46 AM

How to solve this problem  When I try to add the parameter sessionType to the where clause I get and error and I can't figure out how to solve it.since SessionType is an Enum tried using that but  still an error what can I do ?
 
  public Session GetSession (string sessionName, SessionType sessionType)
      {
      if (sessionName == null)
        {
        throw new ContractException(ErrorCode.SessionNameIsNullOrEmpty);
        }
      if (sessionType == null)
        {
        throw new ContractException(ErrorCode.SessionTypeIsNullOrEmpty);
        }
      Session xmlsessions;
      Session session3;
      try
        {
        var sessionDoc = XDocument.Load(SessionFILE);
        xmlsessions = from sessions in sessionDoc.Descendants("session")
                where sessions.FirstAttribute.Value.ToString() == sessionName
                where (SessionType)sessions.FirstAttribute.Value.ToString() == sessionType.ToString()
                select sessions;
        if (xmlsessions == null)
          {
          throw new ContractException(ErrorCode.SessionNotFound);
          }
        Session session2 = new Session
        {
          AdminFeeCost = xmlsessions.AdminFeeCost,
          Certifications = xmlsessions.Certifications,
          ClassTimes = xmlsessions.ClassTimes,
          ConsultingBaseCost = xmlsessions.ConsultingBaseCost,
          ConsultingStartDate = xmlsessions.ConsultingStartDate,
          GridParagraph = xmlsessions.GridParagraph,
          LengthInWeeks = xmlsessions.LengthInWeeks,
          PayoffSchedule = xmlsessions.PayoffSchedule,
          PolyCost = xmlsessions.PolyCost,
          RefundPolicy = xmlsessions.RefundPolicy,
          SessionName = xmlsessions.SessionName,
          Template = xmlsessions.Template,
          TotalConsultingHours = xmlsessions.TotalConsultingHours,
          TotalConsultingMonths = xmlsessions.TotalConsultingMonths,
          TotalConsultingMonthsFull = xmlsessions.TotalConsultingMonthsFull,
          TrainingBaseCost = xmlsessions.TrainingBaseCost,
          TrainingEndDate = xmlsessions.TrainingEndDate,
          TrainingSchedule = xmlsessions.TrainingSchedule,
          TrainingStartDate = xmlsessions.TrainingStartDate,
          Type = xmlsessions.Type,
          ValidLocation = xmlsessions.ValidLocation,
        };
        session3 = session2;
        }
      catch (ContractException cx)
        {
        throw new ContractException(cx.ContractErrorCode.ToString(), ErrorCode.SessionNotFound);
        }
      return session3;
      }
[)ia6l0 iii replied to Donnie Talley on 24-Jan-12 12:11 PM
Use these: One of them should work. 

  1. (SessionType)Enum.Parse(typeof(SessionType),sessions.FirstAttribute.Value.ToString());
  2. (sessions.FirstAttribute.Value == (int)sessionType); 

And how are the attributes stored in the SessionFile?
And what is the error you get?

D Company replied to Donnie Talley on 24-Jan-12 12:20 PM
Hello friend,

instead of using
         where (SessionType)sessions.FirstAttribute.Value.ToString() == sessionType.ToString()

use this

where (SessionType)sessions.FirstAttribute.Value== sessionType.ToString()

let me know if it doesnot work!!

Regards
D

smr replied to Donnie Talley on 31-Jan-12 04:25 AM
hi

A SessionParameter object is typically used in order to include the value of an HttpSessionState variable in theWhere clause of a database query. The SessionField property identifies the session variable from which theSessionParameter retrieves a value.


follow
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sessionparameter.aspx