none
Problem with ESQL RRS feed

  • Question

  • Hi,

    I have a problem with the ESQL.

    I declare a class

    public class PatData
    {
      public int achAccId;
      public DateTime patDOBirth;
      public string patGender;
    }
    string cmd = "Select h.achAccId, p.patDOBirth, p.patGender from PatientEntities.AccBases as a, PatientEntities.AccHosps as h, PatientEntities.Patients as p Where h.achAccID = 57348 and p.patPatId = a.acbPatId and h.achAccId = a.acbAccId";

    ObjectQuery<dbdatarecord>queryResult = null;

    using (PatientEntities db = new PatientEntities())
    {
      queryResult = db.CreateQuery<dbdatarecord>(cmd);
    }

    if ((queryResult != null) && (queryResult.Count() > 0))
    {
      ...
    }
    queryResult.Count() causes an error : "'achAccID' is not a member of type 'PatientModel.AccHosp' in the currently loaded schemas"
    I checked the AccHosp has achAccID.

    So what is the real problem? </dbdatarecord></dbdatarecord>

    <dbdatarecord><dbdatarecord>Thank you very much.</dbdatarecord></dbdatarecord>

    Wednesday, March 6, 2013 2:45 AM

Answers

  • Hi,

    The problem is not ESQL itself. The ObjectContext need refresh. ie. db.Refresh(...); But it is very slow. I have to give up, not use ESQL.

    • Marked as answer by peter 9 Sunday, March 10, 2013 11:46 PM
    Sunday, March 10, 2013 11:46 PM

All replies

  • On 3/5/2013 9:45 PM, peter 9 wrote:

    Hi,

    I have a problem with the ESQL.

    I declare a class

    public class PatData
    {
       public int achAccId;
       public DateTime patDOBirth;
       public string patGender;
    }
    string cmd = "Select h.achAccId, p.patDOBirth, p.patGender from PatientEntities.AccBases as a, PatientEntities.AccHosps as h, PatientEntities.Patients as p Where h.achAccID = 57348 and p.patPatId = a.acbPatId and h.achAccId = a.acbAccId";

    ObjectQuery<dbdatarecord>queryResult = null;

    using (PatientEntities db = new PatientEntities())
    {
       queryResult = db.CreateQuery<dbdatarecord>(cmd);
    }

    if ((queryResult != null) && (queryResult.Count() > 0))
    {
       ...
    }
    queryResult.Count() causes an error : "'achAccID' is not a member of type 'PatientModel.AccHosp' in the currently loaded schemas"
    I checked the AccHosp has achAccID.

    So what is the real problem? </dbdatarecord></dbdatarecord>

    <dbdatarecord><dbdatarecord>Thank you very much.</dbdatarecord></dbdatarecord>

    Below is what the object properties should look like.

    public class PatData
    {
      public int achAccId {get; set;}
      public DateTime patDOBirth {get; set;}
      public string patGender {get; set;}
    }

    http://msdn.microsoft.com/en-us/library/bb384054.aspx

    Also, the PatData if it's PatData.cs in the solution may need to be decorated with namespace PatientModel.AccHosp, as 'PatientModel.AccHosp' looks to be a namespace.
     namespace
    {
        class
       {
        }
    }

    Wednesday, March 6, 2013 3:18 AM
  • 

    Hi,

    Thank you for your help.

    To simplified the question, I made mistake. I work on WCF, entityframe work. The PatData actually like

    [DataContract]
    public class PatData
    {
      [DataMember] 
      public int achAccId;

      [DataMember]
      public DateTime patDOBirth;

      [DataMember]
      public string patGender;
    }

    PatientEntities is an ObjectContext. Also I found under PatientModel.edmx file, under <EntityType Name="AccHosp"> there is <property Name="achAccID" Nullable="false" Type="int">

    Wednesday, March 6, 2013 3:52 AM
  • On 3/5/2013 10:52 PM, peter 9 wrote:




    Hi,

    Thank you for your help.

    To simplified the question, I made mistake. I work on WCF, entityframe work. The PatData actually like

    [DataContract]
    public class PatData
    {
       [DataMember]
       public int achAccId;

       [DataMember]
       public DateTime patDOBirth;

       [DataMember]
       public string patGender;
    }

    PatientEntities is an ObjectContext. Also I found under PatientModel.edmx file, under <EntityType Name="AccHosp"> there is <property Name="achAccID" Nullable="false" Type="int">

    That PatData class/object is not right. It's not right. There are no getter/setter.

    <http://msdn.microsoft.com/en-us/library/ms733127.aspx>

    You don't have to do the properties of the object like is being shown in the example in the above link, which has a private backing variable that the public property is using in the object.
     http://msdn.microsoft.com/en-us/library/bb384054.aspx

    <copied>
    In C# 3.0 and later, auto-implemented properties make property-declaration more concise when no additional logic is required in the property accessors. They also enable client code to create objects.
     ((When you declare a property as shown in the following example, the compiler creates a private, anonymous backing field that can only be accessed through the property's get and set accessors.))

    <end>

    Sooner or later you are going to get bit on the client-side, because the object you have is not correct.

    An EF entity is an implicit serialized datacontract to WCF, if you are using the Model of the EF or model first approach. That means that you can send those EF entites as is through the WCF service.

    If you went and looked at the code that defines an EF entity, an object, then you will see the property's get and set accessors the entity/object is using.

    I don't know how you are getting that object to work on the client side, when it is serialized by WCF or when the client sends the object back to WCF. But I am telling you that you are going to get bit in the way you have that PatData object defined.

    Wednesday, March 6, 2013 5:42 AM
  • Hi,

    Thank you again.

    At the begining I used the PatData, I got an error. To debug, I made the code simple, So PatData is really not used here, I should not leave PatData here. I think the error is caused by ESQL or the DataModel.

    Wednesday, March 6, 2013 11:11 PM
  • Hi,

    The problem is not ESQL itself. The ObjectContext need refresh. ie. db.Refresh(...); But it is very slow. I have to give up, not use ESQL.

    • Marked as answer by peter 9 Sunday, March 10, 2013 11:46 PM
    Sunday, March 10, 2013 11:46 PM