Does anyone know a good approach using Entity Framework for the problem described below?
I am trying for our next release to come up with a performant way to show the placed orders for the logged on customer.
Of course paging is always a good technique to use when a lot of data is available I would like to see an answer without any paging techniques.
Here's the story: a customer places an order which gets an orderstatus = PENDING. Depending on some strategy we move that order up the chain in order to get it APPROVED.
Every change of status is logged so we can see a trace for statusses and maybe even an extra line of comment per status which can provide some extra valuable information to whoever sees this order in an interface.
So an Order is linked to a Customer. One order can have multiple orderstatusses stored in OrderStatusHistory.
In my testscenario I am using a customer which has 100+ Orders each with about 5 records in the OrderStatusHistory-table.
I would for now like to see all orders in one page not using paging where for each Order I show the last relevant Status and the extra comment (if there is any for this last status; both fields coming from OrderStatusHistory; the record with the highest Id for the given OrderId).
There are multiple scenarios I have tried, but I would like to see any potential other solutions or comments on the things I have already tried.
Trying to do Include() when getting Orders but this still results in multiple queries launched on the database. Each order triggers an extra query to the database to get all orderstatusses in the history table. So all statusses are queried here instead of just returning the last relevant one, plus 100 extra queries are launched for 100 orders. You can imagine the problem when there are 100000+ orders in the database.
Having 2 computed columns on the database: LastStatus, LastStatusInformation and a regular Linq-Query which gets those columns which are available through the Entity-model.
The problem with this approach is the fact that those computed columns are determined using a scalar function which can not be changed without removing the formula from the computed column, etc...
In the end I am very familiar with SQL and Stored procedures, but since the rest of the data-layer uses Entity Framework I would like to stick to it as long as possible, even though I have my doubts about performance.
Using the SQL approach I would write something like this:
WITH cte (RN, OrderId, [Status], Information)
AS
(
SELECT ROW_NUMBER() OVER (PARTITION BY OrderId ORDER BY Id DESC), OrderId, [Status], Information
FROM OrderStatus
)
SELECT o.Id, cte.[Status], cte.Information AS StatusInformation, o.* FROM [Order] o
INNER JOIN cte ON o.Id = cte.OrderId AND cte.RN = 1
WHERE CustomerId = @CustomerId
ORDER BY 1 DESC;
which returns all orders for the customer with the statusinformation provided by the Common Table Expression.
Does anyone know a good approach using Entity Framework?
Does anyone use the PL/SQL Web Toolkit at all? We use it for internal reporting where I work.
However, does anyone have any experiences of it for producing client-facing websites? General advantages/disadvantages compared to other web languages, such as JSP, PHP etc
Need to create a php file so I can send data to an sql server and get data from the server. There must also be a json support because I am doing this for an iphone app. Could you please help me and give me a source code example.
Thanks in advance.
I have a table in the form:
test_name| test_result |
test1 | pass |
test2 | fail |
test1 | pass |
test1 | pass |
test2 | pass |
test1 | pass |
test3 | pass |
test3 | fail |
test3 | pass |
As you can see all test1's pass while test2's and test3's have both passes and fails.
Is there a SQL statement that I can use to return the distinct names of the tests that only pass? E.g. test1
Can't figure this one out... when I execute a select query it shows an explain plan cost of ~4500 and takes ~3 seconds to return. When I wrap that query (no changes) inside of:
select count(*) from (
/*query here*/
)
It times out. It's at 5 minutes and counting now.
I tried this in SQL Developer and Aqua Data Studio -- same results.
Hi,
Is it possible to return a single value and an enumerable collection using LINQ to SQL?
The problem is, I'm trying to do paging across a large recordset. I only want to return 10 rows at a time so I'm using .Skip(20).Take(10) approach.
However I need to know the total number of records so I can show an appropriate page x of y.
Trying to avoid two separate queries.
Thanks
i am trying to create a statement in sql (for a table which holds stock symbols and price on specified date) with avg of 5 day price and avg of 15 days price for each symbol.
table description:
symbol
open
high
close
date
the average price is calculated from last 5 days and last 15 days. i tried this for getting 1 symbol:
SELECT avg(close),
avg(`trd_qty`)
FROM (select *
from cashmarket
WHERE symbol = \'hdil\'
order by `M_day` desc
limit 0,15 ) s
...but I couldn't get the desired the list for showing avg values for all symbols.
While there's lots to like about DataObjects.NET, I've found help resources to be a lean, and can't find a solit example of using DataObjects.NET with RDBMS generated primary keys. It would seem as though D4O won't do inserts against SQL Server unless it's in controll of the key.
Has anyone solved this in the wild?
I have an sql table with data like this:
| theDate (datetime) | theValue (int) |
----------------------------------------
| 2010-05-17 02:21:10 | 5 |
| 2009-03-12 04:11:35 | 23 |
| 2010-02-19 18:16:53 | 52 |
| 2008-07-07 22:54:11 | 30 |
The dates are stored in UTC format in a datetime column, how can I convert them to local time (Norway)? Remember that the UTC-offset is not the same all year because of winter/summer-time.
Hello.
I have a short question. Im my current project I'm using LINQ-to-SQl. That is the best way to determine if table has record with specific ID?
Thanks in advance.
I'm writing java application that is using both SQLite and MySQL using JDBC.
Are there any differences in SQL for those databases? Can I use same queries for both SQLite and MySQL, or is there any db specific stuff, that doesn't work on the other one?
As far I've worked only with MySQL, so I don't really know much about SQLite.
So this my first question here, let's look how it works.
I'm working on a project, which has to to provide a "Native XML WebService" on a SQL Server 2005. The web service and the WSDL generation works fine. But there are troubles with the authentication.
Is it possible to turn the authentication off (The tests and the documentation by Microsoft say no.)?
And if so how?
hello,
i am developing wpf application..
i need your suggestions.
i have to make reports in my application...
so which one is best, by crystal report or by using sql server reporting service..
friends what you say ? give ur suggestion which one is best and why ???
I have a sql statement I am using a simple sort such as the following
Select numbers
From theTable
Order By numbers
What I get in return is the following
1
11
12
14
2
21
22
23
3
35
37
etc...
I want it to be ordered in normal order
1
2
3
4
5
6
etc...
What is the most standard encryption technique used in sql server for asp.net c# enterprise level application? . i am talking with respect to standards like md5 or sh1 etc, hashing
I had a table (Some_Table) with two columns:
A B
-------------------
1 test
2 test
3 test1
4 test1
i would like to return DISTINCT values for column B and it's associated value in column A (first in distinct set), so something like this:
A B
-----------
1 test
3 test1
What is the sql?
I have a single MYSQL Question and need help ASAP.
Database:
Email | Name | Tag
[email protected] |Test Person | TagOne
[email protected] |Test Person | Tag Two
Need an SQL query that will return
Email | Name | Tag
[email protected] |Test Person | TagOne, Tag Two
Any help?
I am created a website using visual studio 2010. On the time of the development of website I am able to access the database.. but after publishing the site using IIS7..i was unable to access the database..the exception occured during that time was "the connection is in the closed state".in IIS7 When I changed the application pool identity to localsystem, it worked.
Data base is installed in the same machine. and server is SQL SERVER 2008 R2
I need to compare tables with the same names in different databases ( Sql Server 2008 ). How using C# code and ADO.Net to identify additions, deletions, updates. Is DataReader going to work in this scenario without stored procedures ? DataReader seems to be suitable for single database connection, or am I missing something ?
Hi,
I have a StreamReader object that I initialized with a stream, now I want to save this stream to disk (the stream may be a gif or jpg or pdf etc).
SO my code so far is:
StreamReader sr = new StreamReader(myOtherObject.InputStream);
I need to save this to disk (I have the filename).
In the future I may want to store this to sqlserver
I have the encoding type also, which I will need if I store it to sql server right?
Hi,
Is there any way, to save formatted in database from richtextbox?
I've got richtextbox and some parts of text in this are bold.
string s=richtextbox.Text obviously doesn't work.
And If I can get this formatted text how to save it in Ms Sql Server 2005 ?
Should I invest a lot of time trying to figure out an ORM style implementation, or is it still common to just stick with standard SQL queries in python/pylons/sqlalchemy?
I have been searching for a while about how EF utilizes connections to SQL Server DB, and whether it is using Connection pools under the hood, but I couldn't find any details about that.