I run this code:
var cos = from k in _db.klienci_do_trasy where k.klient_id == 5 select k;
but the query send to database is:
SELECT * FROM `klienci_do_trasy`
LIMIT 0, 30
why is it for, there is no condition on klient_id?
What database are you using? If this is really the case, there could be an error in the provider.
Related
I implemented a Linq query in F# that uses this solution to group by multiple columns. It compiles and works half of the time but in the other half of the time the program throws a runtime type miss-match error. Sometimes the AnonymousObject seems to get an int instead of a Nullable<int>, which then causes an error.
let q = query{
for wh in d.Table1 do
where (wh.Date >= vDate)
where (wh.Date <= bDate)
join tae in d.Table2 on
(wh.Table2Key = tae.key)
let key = AnonymousObject<int,int,Nullable<int>>(wh.Table3key,wh.ProjectTableKey,tae.ProjectPhaseKey)
where tae.ProjectPhaseKey.HasValue
groupValBy wh key into g
select {pkey = g.Key.Item2; lphasekey = g.Key.Item3 ; orgk = g.Key.Item1; time = g.Sum (fun x -> x.data) }
}
How can it be, that the types change at runtime? Can anybody give me a hint? Or has an idea how to work around that?
The datagrid that I use on the client is based on SQL row number; it also requires a total number of pages for its paging. I also use the PagedList on the server.
SQL Profiler shows that the PagedList makes 2 db calls - the first to get the total number of records and the second to get the current page. The thing is that I can't find a way to extract that total number of records from the PagedList. Therefore, currently I have to make an extra call to get that total which creates 3 calls in total for each request, 2 of which are absolutely identical. I understand that I probably won't be able to rid of the call to get the totals but I hate to call it twice. Here is an extract from my code, I'd really appreciate any help in this:
var t = from c in myDb.MyTypes.Filter<MyType>(filterXml) select c;
response.Total = t.Count(); // my first call to get the total
double d = uiRowNumber / uiRecordsPerPage;
int page = (int)Math.Ceiling(d) + 1;
var q = from c in myDb.MyTypes.Filter<MyType>(filterXml).OrderBy(someOrderString)
select new ReturnType
{
Something = c.Something
};
response.Items = q.ToPagedList(page, uiRecordsPerPage);
PagedList has a .TotalItemCount property which reflects the total number of records in the set (not the number in a particular page). Thus response.Items.TotalItemCount should do the trick.
I have the following code to enter some data in the database using the class SqlBulkCopy from ADO.NET
using (SqlBulkCopy bulkCopy = new SqlBulkCopy(DCISParameters.ConnectionString))
{
bulkCopy.DestinationTableName = "tbzErgoAnalytical";
bulkCopy.BatchSize = 250;
bulkCopy.ColumnMappings.Add("Column1", "fldESPA");
bulkCopy.ColumnMappings.Add("Column2", "fldEP");
bulkCopy.ColumnMappings.Add("Column13", "fldMISCode");
bulkCopy.WriteToServer(dbTable);
bulkCopy.SqlRowsCopied += bulkCopy_SqlRowsCopied;
}
dbTable is a DataTable object that is passed as a parameter from a method and it contains 7691 rows that i take from an excel file. I have set the batch size to 250. The problem is that 7500 (250 * 30) rows are transferred correctly to the database but then i receive the following error: "Column 'fldMISCode' does not allow DBNull.Value." I am 100% sure that there is no null value in the fldMISCode and i suppose that in the last insert i have only 191 rows left which is less than the batch size (not sure if my assumption in correct). Any idea how to deal with this error? Thanks in advance...
In my domain a node can have several relationships of the same type to other entities. Each relationship have several properties and I'd like to retrieve the nodes that are connected by at least 2 relationships that present a given property.
EG: A relationship between nodes have a property year. How do I find the nodes that have at least two outgoing relationships with the year set to 2012?
Why Chypher query so far looks like this (syntax error)
START x = node(*)
MATCH x-[r:RELATIONSHIP_TYPE]->y
WITH COUNT(r.year == 2012) AS years
WHERE HAS(r.year) AND years > 1
RETURN x;
I tried also nesting queries but I believe that it's not allowed in Cypher. The closest thing is the following but I do not know how to get rid of the nodes with value 1:
START n = node(*)
MATCH n-[r:RELATIONSHIP_TYPE]->c
WHERE HAS(r.year) AND r.year == 2012
RETURN n, COUNT(r) AS counter
ORDER BY counter DESC
Try this query
START n = node(*)
MATCH n-[r:RELATIONSHIP_TYPE]->c
WHERE HAS(r.year) AND r.year=2012
WITH n, COUNT(r) AS rc
WHERE rc > 1
RETURN n, rc
I've looked around and can't find too much. But is it possible to do something like this using HQL in nHibernate:
Session.CreateQuery(#"DELETE FROM MyObject mo
WHERE (mo.AlteredDate + mo.ExpiryDetails.ExpiryTimestamp) < :pNow")
.SetDateTime("pNow", DateTime.Now);
So basically I want to delete all MyObjects from the database where the last time the object was altered (mo.AlteredDate - a DateTime) plus an amount of time such as 2 days and 5 hours (ExpiryDetails.ExpiryTimestamp) is less than now.
Or is it best to retrieve the objects and do the caculation in code using the .NET framework?
Super late to answer, but I did something like this & it works:
IQuery query = Session.CreateQuery("select x from OBJECT x where x.DateTimeForCompare > :dateTimeForCompare2");
query.SetDateTime("dateTimeForCompare2", DateTime.Today);
IList<OBJECT> xx = query.List<OBJECT>();