Linq Queries : Translate Local variable references

Hello !
I'm using the information from this MSDN Blog :
http://blogs.msdn.com/b/mattwar/archive/2007/08/01/linq-building-an-iqueryable-provider-part-iii.aspx
everything works very well except the case when I have a DateTime variable inside the query that I have to translate .
This is my case :
On my database I have the table orders where dt column have Date Type and store only the date.
Now if I have this query :
DateTime dt1 = Convert.ToDateTime("01/01/2012");
var query = db.Orders.Where(c => c.dt == dt1);
If I try to translate , the returned expression is :
SELECT * FROM (SELECT * FROM Orders) AS T WHERE (dt = '01/01/2012 12:00:00 AM')
As you can see the translated query contains the time at the end , and my query everytime return no records.
What can I do that in translated query the value to be only the date without the time.?
I try many variants , I format the variable only to date format , but it's the same thing.
Thank you !

the simpliest solution would be to use the Date-Portion of your DateTime-Object
another Solution would be the ToString method like
c.dt.ToString("MM.dd.YYYY") == dt1.ToString("MM.dd.YYYY")
it may not be exactly like this... but you'll find the right toString method yourself. There is even a toString-Method wich you can pass a CultureInfo-object, but i found the best way for coparing Dates is to provide a const format-string that is used to
compare DateTime-Types.
To put in some extra suggar, you could try to override the DateTime-Equal-Operator-Implementation.

Similar Messages

  • How to create a local object reference variable in teststand sequence file programatically using C#

    I want to create a local object reference variable in a TestStand sequence file programatically using C#.

    Hi,
    Accoring to your reply in this Thread
    http://forums.ni.com/ni/board/message?board.id=330&thread.id=26984
    Just try this example. There you will create a numeric variable during excuting a sequence!
    Hope this is what you are looking for. 
    Please attach all your questions here.
    juergen
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=
    Attachments:
    CTestStandDialog.zip ‏31 KB

  • Reference to a local variable object returned by a method is alive?

    I have an instance method getEmployee().
    This method forms a local variable, Employee and returns it.
    public Employee getEmployee()
    Employee e = new Employee();
    e.setSNo(sNo+=);
    e.setMailBox();
    return e;
    There's another instance method in the same class that calls getEmployee() in this manner:-
    Employee newEmployee = getEmployee();
    newEmployee.printDetails();
    I want to know whether the employee returned by getEmployee() is still alive when we are doing newEmployee.printDetails().
    I am confused because in C, the lifetime of a local variable is limited only to the life time of the function. Once the function finishes, the local variable is considered garbage.
    How does it work in case of Java?

    No, It rarely has any use but can be used to unload things (from a cache for example). However I have never needed to do this. All I know is that finallizers can only be relied on to clear up memory. How or why you would do this is another question.
    The GC runs when memory is low (not any other resource). It calls finalizers when it clears up objects. Therefore the only thing you can reliably release in a finalizer is memory. Other resources can become depleted without heap being depleated so you can't use finalizers to relialy clean up non-memory resources.
    Anyway.
    some more info on escape analysis
    a compile time escape analysis
    http://www.excelsior-usa.com/pdf/StackAlloc.pdf
    This can handle some finalizers
    This does not handle finalizers (marks them all as GLOBAL_ESCAPE
    http://delivery.acm.org/10.1145/330000/320386/p1-choi.pdf?key1=320386&key2=0718563811&coll=Portal&dl=ACM&CFID=15151515&CFTOKEN=6184618
    bit more recent and about runtime optimization (finalizers not handled)
    http://ssw.jku.at/Research/Papers/Ko05/Ko05.pdf
    I don't think that not handling finalizers is too much of a problem. Most objects that will benifit from stackability are small objects anyway (especially the built in wrapper types). Most objects that have custom finalizers tend to be pretty complicated.
    matfud

  • Can I reference a sequence object by a local variabl?

    Hi,
    I create ten sequences in database. In my form, I get a sequence number from different sequence object according to different situations.
    So can I choose one of the seuqences by refering it using a local variable ? such as :
    declare
    first_sequence varchar2(100);
    new_po number(10);
    begin
    first_sequence:='po_number';
    select first_sequence.nextval
    into new_po
    from dual;
    end;
    Thanks
    Stephen

    I cannot see this working as it will complain at compile time. The compiler will look for the envVar as an object on the DB. I believe what you need is something like DBMS_SQL or EXECUTE IMMEDIATE to do what you want.

  • How to assign bean value to a local variable in JSP using struts.

    Hi everybody!
    I've a problem that puzzled me on how to assign a bean value to a local variable like String in JSP using struts.
    we can have someting like this to display the value
    <bean:write name="detailService" property="status" />or
    <bean:define id="theStatus" name="detailService" property="status"/>
         This is country: <%=theStatus%>but an error occured when I tried like this:
    String currentStatus = "<bean:define id="theStatus" name="detailService" property="status"/>";
    or
    String currentStatus = "<bean:write name="detailService" property="status" />";Is there a way to do this?.....
    Any help pretty much appreciated

    Java != JSP.
    The <bean:define> and <bean:write> tags are custom tags meant to appear in the HTML section of a JSP file, as opposed to the scriptlet section. They actually get turned into java code as part of the translation process.
    The <bean:write> tag naturally just writes out what you tell it to.
    The <bean:define> tag defines a local variable, and gives it a value.
    this should do it.
    <bean:define id="theStatus" name="detailService" property="status" type="java.lang.String"/>
    <%
      String currentStatus = theStatus;
    %>With the advent of JSTL, you shouldn't really need to use scriptlet code anymore. Personally I am for 0% scriptlet code in any jsp I write.

  • Does a large amount of "local variable" within a vi cause problems?

    Hello -- I am using Labview 7.0 and have a vi where I am going to end up using about 100 "local variables" for indicators that are displaying data. Since I have a lot of true / false case structures I decided to use these local variables instead of having a mess of wiring all over the vi block diagram. It is intimidating though and I was wondering if it causes slowness in vi's?

    I actually only have about 8 indicators -- but I am in the process of creating control algorithms so I have to use many case structures if I want to keep the code all within Labview (simplicity). I am simply referencing the 8 or so indicator values many many times (100 X) I am attaching a copy of the vi like you asked but just take a look at the right hand side of the while loop on the right -- it shows an example of an algorithm I created today that has to reference the data from sensors. I would love to know what a better way to do this. Thanks!
    Attachments:
    ucb drill control daq 1_7.vi ‏666 KB

  • How many ways to read and write a local variable in a called VI?

    Ciao!
    I'm producing my first TestStand sequence. It is called "FirstAttempt" and it is made by a single step which calls a VI. One of the first dilemmas i encountered realizing this sequence is how to read and write a local variable (created going in Variables -> Locals ('FirstAttempt') -> <right click to insert local>) in the called VI.
    The first way (the only one i tried) is to create a control and an indicator on the VI front panel, connect them to their respective terminals in the connector pane and then specify (going in Step Settings -> Module) that these connectors (shown in the Parameter Name column) are linked to the local variable (selected in the Value column).
    The second way (not tried) consists in using TestStand API: create a Sequence Context reference on the VI front panel, link it to a property node in the block diagram, select the property "Locals" and extract from this the local variable name and value which, i think, can be readable and writable.
    So...
    Are the shown ways correct?
    Are there other ways?
    Knowing that a "local" variable can be considered "global" within the whole sequence, is there the possibility to simply create a reference to the local variable and use the reference in the called VI block diagram in order to save space in the connector pane (if using method 1) or in the block diagram (if using method 2)?
    Thanks!
    Message Edited by aRCo on 09-17-2009 05:09 AM

    Hi,
    Before TestStand 3 you would use the second way you quoted as its the only way.
    But now you would use the first way you quoted. You may still what to pass the SequenceContext if you were going to use the TestStand API. For TestStand 3.x and above you would use this way as the first chose. (Personnelly, I would not pass the SequenceContext into a VI if I know it was never going to be used in that VI.)
    Not sure I understand your final comment, maybe you are liking it to passing the reference of a control to a subVI so that the control can be updated from within the subVI.
    If this is the case and you had a situation where you had a step that was running in parallel with the rest of the steps in the sequence either as a separate thread or execution and were dependent on the contents of the  local variable changing from that parallel running step, then you would have to use the API SetVal method to change the local.
    Hope this is clear.
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • While trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'

    Hi,
    Our PI is getting data from WebSphere MQ and pushing to SAP. So our sender CC is JMS and receiver is Proxy. Our PI version is 7.31.
    Our connectivity between the MQ is success but getting the following error while trying to read the payload.
    Text: TxManagerFilter received an error:
    [EXCEPTION]
    java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'
           at com.sap.aii.adapter.jms.core.channel.filter.ConvertJmsMessageToBinaryFilter.filter(ConvertJmsMessageToBinaryFilter.java:73)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
           at com.sap.aii.adapter.jms.core.channel.filter.InboundDuplicateCheckFilter.filter(InboundDuplicateCheckFilter.java:348)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
    I have searched SDN but couldn't fix it. Please provide your suggestion.
    With Regards
    Amarnath M

    Hi Amarnath,
    Where exactly you are getting this error?
    If you are getting at JMS Sender communication channel, try to stop and start the JMS communication channel and see the status, also use XPI Inspector to get the exact error log.
    for reference follow below blogs:
    Michal's PI tips: ActiveMQ - JMS - topics with SAP PI 7.3
    Michal's PI tips: XPI inspector - help OSS and yourself
    XPI Inspector

  • Local variable problem

    I am making an application that takes an apartment number and number of occupants in that apartment and then displays a number of statistics. So far I haven't had much problem
    except on a what is probably a very simple problem.
    I have two buttons, and when "store" is clicked the info in the textboxes is input to an array.
    My problem is with the next button, "quit", this is where all the info is supposed to be displayed.
    All my variables that I need from "store" are local and are recognized in " the if statement in quit. Ive tried declaring them outside of the if statement, but it hasn't been working.
    {code}
    public void actionPerformed(ActionEvent event)
                   Object source = event.getSource();
                   Apartment input;
                   if (source == store)
                        Integer aptNo = Integer.parseInt(input1.getText());
                        Integer occup = Integer.parseInt(input2.getText());
                        input = new Apartment(aptNo, occup);
                        if(aptNo > BUILDING_SIZE)
                             JOptionPane.showMessageDialog(null, "That apartment number doesn't exist.");
                        else if(occup > MAX_OCCUPANTS)
                             JOptionPane.showMessageDialog(null, "Too many occupants, only 20 are permitted per apartment.");
                        else
                             occupants[aptNo] = occup;
                             input1.setText("");
                             input2.setText("");
                             JOptionPane.showMessageDialog(null, input.getNumber(occupants));
                   if (source == quit)
                   // I need the variables aptNo and occup in here to put into my methods for output, but I don't know how to get them.     
    {code}

    EmmCeeVee wrote:
    Thank you for all of the responses, it really helps me out.
    Obviously my knowledge of local variables is hurting as I switched it around as your said and declared the aptNo and occup outside of the if's.
    All I need is for the quit button to look at the array ( which has just been modified by the sotre button) and output a bunch of results.
    Heres where im at:Your problem is of scope of the variables.
    Here whatever variable you defined in actionPerformed they are local for that method (they are out of scope when the method is finished/called again), Upon this, the actionPerformed is called twice one for store and another time for quit. So you cant expect the value stored at store should be there still when you all quit
    If you want those values available on both the actions then make them a class level variables.
    Below is a sample program, might help you.
    class Employee
         String empName = null;
         int empNo;
         Employee(String eName,int eNmbr)
              this.empName = eName;
              this.empNo = eNmbr;
    class CheckVariableScope
            Employee empOb; // Here
         int eNo;
         String eName = null;
         public void checkScope(String action)
                    //Instead of defining Employee reference variable, eNo and eName  in checkScope method, define it @ class level.
                    // in your case they are Apartment input, Integer aptNo and Integer occup
                     // like above i did.
                     // If i comment the class level variable and uncomment method variable, this program also give the same error.
              //Employee empOb;
              //int eNo;             
              //String eName = null;
              if (action.equals("Store") )
                        eNo = 10;
                        eName = "Bob";
                        empOb = new Employee(eName, eNo);
                        System.out.println("The eName is : "+empOb.empName+" , empNo is : "+empOb.empNo);
                   if (action.equals("quit"))
                        System.out.println(" eNO from Object is : "+empOb.empNo);
                        System.out.println(eNo); //Error: may not have been intitialized
         public static void main (String st[])
              CheckVariableScope ob = new CheckVariableScope();
              ob.checkScope("Store");
              ob.checkScope("quit");
    }

  • GetDescriptions() of an object loaded from local variable 'itemDeploymentResult'

    Hi
    We are urgrading our SAP MII ( purely Java ) systems from 7.31 Sp5 to 7.40 and we got stuck at Configuration phase. We are getting the following error during Queue validation.
    Checking of deployment queue completed with error. java.lang.NullPointerException: while trying to invoke the method com.sap.sdt.j2ee.tools.deploymentmgr.DeploymentManagerItemResultIF.getDescriptions() of an object loaded from local
    variable 'itemDeploymentResult'.
    I looked in the trace files under SUM/sdt/trc directory and found the following information.
    Jul 3, 2014 9:52:16 AM
    [Error]:
    com.sap.sdt.executor.module.ModuleExecutor [Thread[UC-3,5,main]]: A
    problem has occurred:
    com.sap.sdt.executor.exception.StepExecutionException: Problem while
    trying to execute operation on service validate-queue. The following
    problem has occurred java.lang.reflect.InvocationTargetException. CSN
    Component BC-UPG-TLS-TLJ.
    Checking of deployment queue completed with error.
    java.lang.NullPointerException: while trying to invoke the method
    com.sap.sdt.j2ee.tools.deploymentmgr.DeploymentManagerItemResultIF.getDescriptions() of an object loaded from local
    variable 'itemDeploymentResult'
    Jul 3, 2014 9:52:16 AM
    [Error]:
    com.sap.sdt.executor.module.ModuleExecutor [Thread[UC-3,5,main]]:
    Checking of deployment queue completed with error.
    Jul 3, 2014 9:52:16 AM
    [Error]:
    com.sap.sdt.executor.module.ModuleExecutor [Thread[UC-3,5,main]]:
    java.lang.NullPointerException: while trying to invoke the method
    com.sap.sdt.j2ee.tools.deploymentmgr.DeploymentManagerItemResultIF.getDescriptions() of an object loaded from local
    variable 'itemDeploymentResult'
    We have 26 GB left on our Drive and have also upgraded JSPM to 7.31 Sp8. We are using SUM10SP05_9.
    Appreciate your quick help

    Hi Amarnath,
    Where exactly you are getting this error?
    If you are getting at JMS Sender communication channel, try to stop and start the JMS communication channel and see the status, also use XPI Inspector to get the exact error log.
    for reference follow below blogs:
    Michal's PI tips: ActiveMQ - JMS - topics with SAP PI 7.3
    Michal's PI tips: XPI inspector - help OSS and yourself
    XPI Inspector

  • How to specify a unique integer for each local variable defined in TestStand?

    I have a .net application that reads all TestStand local variables, but for the .net application each local variable should have a unique integer number. Iterating through the locals and storing the index is not a good solution, because if a local variable is moved or deleted, the index will change.
    Does anyone know how to do this in TestStand or having an idea how to this in my .net application?
    Thanks.

    Thanks Doug for your reply. Using a GUID is not an option because this ID is too long. I will try to explain why I need this ID for. I have a lot of C# code that generates code to deal with a lot of instruments. For example to configure a device, user defined variables can be used to specify some settings or to store results. These variables are not stored in the generated code with a name but with an integer number. Now I want to try to be use all our existing device driver code with the TestStand sequencer. So, I need a translation between the name of a TestStand local variable and an integer number. After constructing the interface to my code I want to read all the variables from TestStand and now I need the integer ID to do the mapping to my variables. I know that I can use use your proposition 2 by encoding the unique ID into the name of the variable and parse the name of the variable to get it back, but this is not an automated way. This will be rather difficult if there are several hundreds of variables. For this reason I am looking for an alternative way. Looking forward for your response. Best regards   

  • Catch-22: need to assign a local variable within an anonymous class

    static boolean showMessage(Window parent, String button0, String button1)
        throws HeadlessException {
              final Window w = new Window(parent);
              Panel p = new Panel(new GridBagLayout());
              final Button b[] = new Button[]{new Button(button0), (button1 != null) ? new Button(button1) : (Button)null};
              boolean rval[]; //tristate: null, true, false
              w.setSize(100, 50);
              w.setVisible(true);
              //add b[0
              gbc.fill = GridBagConstraints.HORIZONTAL;
              gbc.gridx = 0;
              gbc.gridy = 3;
              p.add(b[0], gbc);
              //add b[1]
              if (button1 != null) {
                   gbc.fill = GridBagConstraints.HORIZONTAL;
                   gbc.gridx = 1;
                   gbc.gridy = 3;
                   p.add(b[1], gbc);
              w.add(p);
              w.pack();
            w.setVisible(true);
            //actionListener for button 0
              b[0].addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                             if (e.getSource() == b[0]) {
                                  w.setVisible(false);
                                  rval = new boolean[1];
                                  rval[0] = true;
              //actionListener for button 1
              if (button1 != null) {
                   b[1].addActionListener(new ActionListener() {
                             public void actionPerformed(ActionEvent e) {
                                  if (e.getSource() == b[1]) {
                                       w.setVisible(false);
                                       rval = new boolean[1];
                                       rval[0] = false;
            while (true) {
                 try {
                      if (rval[0] == true || rval[0] == false) //should trigger NullPointerException
                           return rval[0];
                 } catch (NullPointerException e) { }
         }catch-22 is at
    rval = new boolean[1];
    rval = false;javac whines: "local variable rval is accessed from within inner class; needs to be declared final"
    How do I assign to rval if it's declared final?
    Or at the very least, how do I get rid of this error (by all means, hack fixes are okay; this is not C/C++, I don't have to use sanity checks)?
    I'm trying to make a messagebox in java without using JOptionPane and I'm trying to encapsulate it in one method.
    And I'm far too lazy to make a JNI wrapper for GTK.

    dcminter wrote:
    How do I assign to rval if it's declared final?You don't and you can't. You're not allowed to assign to the local variable of the outer class for extremely good reasons, so forget about trying.
    Or at the very least, how do I get rid of this errorIf you don't want the side effect, then just use an inner class variable or a local variable.
    If you want the side effect then use a named class and provide it with a getter and setter.
    Finally, in this specific case because you're using an array object reference, you could probably just initialise the array object in the outer class. I.e.
    // Outer class
    final boolean[] rval = new boolean[1];
    // Anonymous Inner class
    rval[0] = true; // No need to intialize the array.
    I declared it as an array so that it would be a tristate boolean (null, true, false) such that accessing it before initialization from the actionPerformed would trigger a NullPointerException.
    Flowchart:
    is button pressed? <-> no
    |
    V
    Yes->set and return
    Is there a way to accomplish this without creating a tribool class?

  • Convert local variable to global - labView

    I have a sequence with a VI that contains a local variable array. Now I need that data saved for use by a VI in a later sequence. Can locals be converted to globals or must it be re-created and all references to it changed?
    Thanks,
    jvh 

    Hi,
    If you are using the SequenceContext as the reference, then your lookup string to your variable would need to change.
    eg "Locals.MyArray" would become "StationGlobals.MyArray"
    Does this help
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • How to use local variables to pass an image mask correctly

    I'm kind of new to labview but i'll try to explain the problem as best as i can: I'm trying to pass an image mask (basically an image) to the next iteration of a while loop using local variables. I think the image passes through the loop with the local variable but i can't read from it correctly for some reason. And I don't think the problem has to do with local variables because i've tried using shift registers and that didnt work either. I think the problem is that you need to do something to read the image correctly again, like using IMAQ copy or something (that didnt work tho), but i can't figure out what the problem is. Does anyone know what the problem is? I know this isnt a great explanation and if its too confusing i could send some snapshots of the program or something. Any help would be greatly appreciated though.
    Thanks,
    Will

    So i attached 2 snapshots of the program to give a better idea of the problem. The first snapshot shows an image getting written to the local variable SavedMask. The second snapshot, which is run on the next iteration of a while loop, shows the local variable SavedMask being read to other image operations. When i run the program, the SavedMask image is always displayed correctly on the front panel, but i can't read from it for whatever reason. I think the problem could be like you said, that im only passing an imaq reference, and i think theres a certain way to extract the image data. Do you know the correct way to extract the image data or how to pass the image data and not just a reference to the data.
    Attachments:
    first.jpg ‏81 KB
    second.jpg ‏68 KB

  • How I Creat a Local Variable to Boolean Key If I but this Boolean Key in Cluster in Fron Panel

    I build a cluster on Fron Panel and I put in it Boolean Key (Square LED) .
    I want to creat a local variable to this object , how can i creat it.
    the option which I get are
    Property Node
    Reference
    Invoke Node

    Hi,
    You create a local variable of the cluster first. Then you can access any of the items in the cluster using Unbundle/Bundle or Unbundle by Name/ Bundle by Name tools.
    Hope this helps
    Ray Farmer
    Regards
    Ray Farmer

Maybe you are looking for