|
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[^]
to translate local variable references in linq queries.
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 !
|
|
|
|
|
Try:
var query = db.Orders.Where( c => c.dt.Date == dt1.Date);
This should effectively cause the times to be the same for both dates.
|
|
|
|
|
Doesn't work.
The problem is that however the query is formatted , the return translated query will be :
SELECT * FROM (SELECT * FROM Orders) AS T WHERE (dt = '01/01/2012 12:00:00
AM')
and so the dt column from database is already a date type and only hold the date .
The problem is not how the query is formatted , but how is translated with the methods from the link I posted.It seems that a datetime value (even formatted with only the date part , is translated to Date + Default time "12.00.00".
So what modifications should made on the code at the link that I posted in order to modify only for date types.
|
|
|
|
|
var query = db.Orders.
Where( c => c.dt.Year == dt1.Year && c.dt.Month == dt1.Month && c.dt.Day == dt1.Day );
The Year, Month and Day properties should translate to SQL DATEPART() functions.
(It does in LINQPad).
|
|
|
|
|
dilkonika wrote: What can I do that in translated query the value to be only the date without the time.? There is no point in time that can be defined without time. The DateTime object is a decimal; the integer part holds the days, the fractional part holds the time.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
If I understand correctly, your issue is that your database only has a DATE value (01/01/2015) But when you try to query the database, the matching variable has the time included (01/01/2015 12:00:00 AM) so the query never finds any matches???
Try this:
DateTime dt1 = Convert.ToDateTime("01/01/2012");
var query = db.Orders.Where(c => c.dt.ToString() == dt1.ToString("d"));
|
|
|
|
|
Exception:Thrown: "Object reference not set to an instance of an object." (System.NullReferenceException)
A System.NullReferenceException was thrown: "Object reference not set to an instance of an object."
namespace WSDL1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.output.Text = "Querying the web service...";
WSDL1.Query.FindConfigurationItemsClient soap = new WSDL1.Query.FindConfigurationItemsClient();
//soap.ClientCredentials.UserName.UserName = "testsoap1";
//soap.ClientCredentials.UserName.Password = "testsoap1";
WSDL1.Query.FindConfigurationItemsRequest request = new WSDL1.Query.FindConfigurationItemsRequest();
WSDL1.Query.FindConfigurationItemsResponse response = new WSDL1.Query.FindConfigurationItemsResponse();
--> request.applicationContext.application = "SOAPUI";
--> request.searchCriteria.name = this.name.Text;
try
{
response = soap.FindConfigurationItems(request);
this.output.Text = "Quering.." + response.configurationItems + "\n";
}
catch (Exception error)
{
this.output.Text = "Error : " + error + "\n";
}
}
}
}
|
|
|
|
|
Unless I'm missing something there is not enough code to replicate. It looks like you need to initialize request.applicationContext and / or request.searchCriteria.
Jack of all trades, master of none, though often times better than master of one.
|
|
|
|
|
put a breakpoint in and start debugging. You need to tell us where exactly the exception is thrown.
Also, please use
code
tags for showing code as this comes out more readable.
|
|
|
|
|
V. wrote: Also, please use
code
tags No, they should use <pre> tags.
|
|
|
|
|
I do hope you meant that as a joke ...
|
|
|
|
|
This is what it looks like with code tags
This is what it looks like with pree tags.
And is the correct way.
|
|
|
|
|
the button doing this:
code says code
the button doing this:
var says var.
yes the tags are named differently, I know that, but I wanted to point it out to the OP who's pretty new to the site (and is, considering his question, a beginner)
Your comment is not helpful in any way and it does not add anything to the solution.
|
|
|
|
|
Your original suggestion is ambiguous, it says "please use code tags", it does not mention any buttons.
V. wrote: Your comment is not helpful in any way and it does not add anything to the solution. My comment was directed to you.
|
|
|
|
|
This conversation isn't going anywhere, so I suggest we just drop it.
|
|
|
|
|
It may be helpful to point this out in the "bugs" forum, as it may still confuse other people.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
It could be the soap.FindConfigurationItems returns null, in that case response don't receive an object coming from FindConfigurationItems method. check your request variable if it returns a value.
You can't use response object when soap.FindConfigurationItems returns null.
|
|
|
|
|
|
If you're saying that you have some (entity) class definitions and want to know how to derive a database from them, then look at the Entity Framework "Code First" (versus the database / model first) approach, which can generate an SQL Server database from "code".
|
|
|
|
|
|
Here's a link that may help:
https://msdn.microsoft.com/en-ca/data/jj679962.aspx
You may only need to some minimal refactoring to indicate parent and child relationship.
|
|
|
|
|
|
I don't know what you mean when you say "... EF does not want the whole object but the ID only have the objects.".
EF will generate a primary key for a property that is or ends in "ID".
A relation is simply a statement such as:
public IList<Order> Orders { get; set; }
EF will create (entity model) relationships using the above "ID's" and "relation" statements.
I haven't used "xsd2Code" but when I paste "layered XML" in Visual Studio using Edit | Paste Special | Paste XML as classes, all the "layers" are converted to classes and a corresponding "relation" statement.
I've used the above to generate classes into which XML from 3rd-party web services was de-serialized; with no refactoring needed.
|
|
|
|
|
Hi there. I'm having a problem to create a program to get information from a website. First thing that I did was to put the login information with a HtmlElement, first I get the element with GetElementById and then I set the attribute, for click on login I get the element by button name and then I invokeMember("click"). It works fine but the problem is after this, the buttons are all in this way:
<img src="_imagens/sistemas/fig_PROJETOS_large.gif" onclick="sistema('PROJETOS','Acompanhamento de Projetos')" alt="Acompanhamento de Projetos" border="0">
So it does not have an ID, it is just calling the javascript function sistema that has some arguments. My question is, how I can run this button from a c# program since I can't found it by ID and then do a InvokeMember to click in this button? I tried to use webBrowser.Document.InvokeScript and others way but nothing worked to me.
Thanks for now.
|
|
|
|