|
This is probably the result of using EF against one of the desktop versions of a database, don't support stored procs.
It is also the way of the new developer, use linq for everything. TSQL is not considered and not learnt because they can just wire up EF. But then I'm old school
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You need to group the set.
Have a look at this[^] example.
|
|
|
|
|
Thanks!
I got thtis to work, but I can't figure out how to insert my 2 joins, and get those values all in 1 result set
Dim pResults = _
(
From cohc In context.Order_History_Cart
Where cohc.PartNumber = "24-FLP44"
Group By cohc = New With
{
cohc.Qty,
cohc.Cost,
cohc.Price<br>
} Into group
Select New With
{
.totalQty = group.Sum(function(q) q.Qty),
.totalCost = group.Sum(function(c) c.Qty * c.Cost),
.TotalPrice = group.Sum(function(p) p.Qty * p.Price)<br>
}
)
<pre>
|
|
|
|
|
I'm new to EF, so bear that in mind..
I'm using WPF 4.5 and EF against a SQLite DB. EF was installed when I installed dotConnect for SQLite[^].
I have a WPF user control that calls into the DAL. However, in DESIGN mode the view is showing the error
"Connection string "MyConnectionString" could not be found in the configuration file."
However, the app.config DOES have the connection string.
Anyone know what's going on?
If it's not broken, fix it until it is
|
|
|
|
|
Been there done that, but in WCF.
In design time you're apparently not using the app.config you think you are.
There's a description and kind of solution to one of the ways this problem can occur here[^].
|
|
|
|
|
I am facing some problem with database connection .can anyone guide me?so i can explain my problem
|
|
|
|
|
Explain your problem and someone may be able to offer some ideas on how to overcome them.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
1) What database software are you using?
2) What are you trying to connect to what?
3) What have you tried?
4) What is the error?
We need a lot more detail before we can start to answer your problem.
Mongo: Mongo only pawn... in game of life.
|
|
|
|
|
First, I no nothing at all about C++...
We need to use SQLite for cross platform compatibility. We would like to have one copy of DB code in C++ and somehow make requests/ send command into it from C#.
One possibility is to have the C++ portion send/receive its data from C# as JSON. In C# I can easily convert the JSON to C# objects and vice versa.
Anyone done this? Any tips/advice/pointers?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
OK.
Or C# can call a C++ DLL with P/Invoke?
|
|
|
|
|
I have few questions about SQL/C# transaction.
1/ How can you add transaction functionality to your stored procedure without locking anything ( I know there is different isolation level, but I'm not sure which one to use )
2/ I need to use transaction just for the sake of rolling back the changes if there was an exception in the middle of the procedure. so I really don't care about locking tables. which isolation level should I use.
|
|
|
|
|
Tunisiano32 wrote: How can you add transaction functionality to your stored procedure without
locking anything ( I know there is different isolation level, but I'm not sure
which one to use ) Locking is done when writing. The isolation levels are for specifying what you want to read.
Tunisiano32 wrote: I need to use transaction just for the sake of rolling back the changes if there
was an exception in the middle of the procedure. so I really don't care about
locking tables. which isolation level should I use. Sounds like the procedure consists of multiple steps that can fail individually, and those updates might lock multiple tables while processing.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
READ UNCOMMITTED is the isolation level you are looking for I think. This will allow dirty reads, but almost eliminate all locking. Writing will lock the affected tables, but if others READ UNCOMMITTED they should be fine. If you have to lock the table in order the rollback the process then you really have no choice but to lock it.
|
|
|
|
|
So I had someone help me write this years ago.
It's a Navigator fly out tab, in which if your working on a product in the editor, you can activate the tab, and the tab will populate with lets say 4 products before and 4 products after the selected product in the database table. This is so you don't have to go back to the index to load the next or previous product.
Since SQL Linq doesn't support the custom SQL Server Function, I need to think or create an alternative way to do this.
I guess I can create a List(Of with a blank column, and then go back and fill in the row numbers
get the row number of the item and ask for -3 and +3 of the row.
Just looking for some suggestions.
Here's the old TSQL
WITH CTE AS
(
SELECT DISTINCT
ProductID
, PostageImage
, PartNumber
, ShortDescription
, Price
, Thumbnail
, ActionThumbnail1
, ActionThumbnail2
, ActionThumbnail3
, FlatFee
, FlatFeeName
, VendorName
, ROW_NUMBER() OVER(ORDER BY PartNumber DESC) AS RowId
FROM PRODUCTINFO p
), CTE1 AS (
SELECT RowId FROM CTE WHERE PartNumber = @PartNumber
)
SELECT * FROM CTE WHERE RowId BETWEEN (SELECT RowId-4 FROM CTE1) AND (SELECT RowId+3 FROM CTE1) ORDER BY PartNumber
This is what I was building in Linq Pad. It's pretty weak now, but I'm getting an idea of what I can do. But before I go off in some strange direction that will lead nowhere or be super slow, I thought I would just try and get a general consensus on this.
I tried to mark it as code but it gets chopped off, end of the day for me, going home now.
Dim p_partNumber as string = "06-SM4"
Dim context as new DBcontext
Dim ordersAsList = _
(
From pi in context.ProductInfo
Select pi
).ToList()
Dim orders = _
(
From pi in ordersAsList
take 3
Select
pi.ProductID
)
orders.Dump()
|
|
|
|
|
A custom extension method is probably the simplest option here:
C#:
static class Extensions
{
public static IEnumerable<T> TakeWindow<T>(this IEnumerable<T> source, Func<T, bool> pivot, int numberBefore, int numberAfter)
{
if (source == null) throw new ArgumentNullException("source");
if (pivot == null) throw new ArgumentNullException("pivot");
if (numberBefore < 0) throw new ArgumentOutOfRangeException("numberBefore");
if (numberAfter < 0) throw new ArgumentOutOfRangeException("numberAfter");
if (numberBefore == 0)
{
return source.SkipWhile(x => !pivot(x)).Take(1 + numberAfter);
}
return TakeWindowIterator(source, pivot, numberBefore, numberAfter);
}
private static IEnumerable<T> TakeWindowIterator<T>(IEnumerable<T> source, Func<T, bool> pivot, int numberBefore, int numberAfter)
{
var queue = new Queue<T>(numberBefore);
foreach (T item in source)
{
if (queue != null && pivot(item))
{
foreach (T previous in queue)
{
yield return previous;
}
queue = null;
yield return item;
}
else if (queue == null)
{
if (numberAfter == 0)
{
yield break;
}
yield return item;
numberAfter--;
}
else
{
if (queue.Count == numberBefore)
{
queue.Dequeue();
}
queue.Enqueue(item);
}
}
}
}
VB.NET:
Module Extensions
<System.Runtime.CompilerServices.Extension>
Public Function TakeWindow(Of T)(ByVal source As IEnumerable(Of T), ByVal pivot As Func(Of T, Boolean), ByVal numberBefore As Integer, ByVal numberAfter As Integer) As IEnumerable(Of T)
If source Is Nothing Then Throw New ArgumentNullException("source")
If pivot Is Nothing Then Throw New ArgumentNullException("pivot")
If numberBefore < 0 Then Throw New ArgumentOutOfRangeException("numberBefore")
If numberAfter < 0 Then Throw New ArgumentOutOfRangeException("numberAfter")
If numberBefore = 0 Then
return source.SkipWhile(Function (x) Not pivot(x)).Take(1 + numberAfter)
End If
Return TakeWindowIterator(source, pivot, numberBefore, numberAfter)
End Function
Private Iterator Function TakeWindowIterator(Of T)(ByVal source As IEnumerable(Of T), ByVal pivot As Func(Of T, Boolean), ByVal numberBefore As Integer, ByVal numberAfter As Integer) As IEnumerable(Of T)
Dim queue As New Queue(Of T)(numberBefore)
For Each item As T In source
If queue IsNot Nothing AndAlso pivot(item) Then
For Each previous As T in queue
Yield previous
Next
queue = Nothing
Yield item
ElseIf queue Is Nothing Then
If numberAfter = 0 Then
Return
End If
Yield item
numberAfter -= 1
Else
If queue.Count = numberBefore Then
queue.Dequeue()
End If
queue.Enqueue(item)
End If
Next
End Function
End Module
Usage:
Dim p_partNumber As String = "06-SM4"
Using context As New DBcontext
Dim orders = context.ProductInfo
.OrderBy(Function(p) p.PartNumber)
.TakeWindow(Function(p) p.PartNumber = p_partNumber, 4, 3)
orders.Dump()
End Using
NB: It won't be as efficient as the SQL query, but it should be more efficient than storing the entire table in a list.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 5-Aug-15 14:15pm.
|
|
|
|
|
I didn't know you can do that.
I know how slow it can get when the record count get high. That's why I didn't want to do the list.
I'll give that a try for now, and then redesign the whole thing later. I knew that using special DB function would take a tool in the future when I implemented it.
Thanks Richard!
|
|
|
|
|
Works like a charm. Took awhile to figure out how to implement it.
Did you write that? it's pretty elegant and wild in how it works.
It would of taken me months to figure that out! But that should be the most complex TSQL remaining in my program.
Oh, this conversion I'm making is mentally draining on me every day, but I'm 1/2 way there now.
The reward will pay off for me when done. Thanks again for taking the time to write that, that was beyond my current knowledge level.
|
|
|
|
|
jkirkerx wrote: Did you write that?
Yes. It seemed like the logical approach. The hardest part was choosing a name!
jkirkerx wrote: it's pretty elegant and wild in how it works.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I've just made a minor modification, to cope with the possibility that more than one item in the input sequence could match the pivot predicate:
If queue IsNot Nothing AndAlso pivot(item) Then
It probably won't happen with your data, but better safe than sorry!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Got It!
Thanks, Does work great! pretty fast as well
|
|
|
|
|
I have this report for sales rep margin in Account Mate for DOS, that uses FoxPro for database table file, .dbx
The item tables or DB files does not have a column for sales rep and order dates, so I can't go to the table directly to get my data.
So without knowing or even where to start to write this in pure SQL, I wrote 2 functions
1. Get Invoices that match the sales rep and start and stop dates, and store it in a List(of invoices)
2. loop a function that targets items by invoice number, and get the cost, price, qty, etc.
When you have 500 invoices, it takes forever to run, slowing down fixing my other problems, which may be fixed now.
Do you think it's possible to merge these statements into a single statement. Plus if so, a nudge in the right direction. I hate this old Fox Pro stuff, it was before my time.
SELECT
h.FINVNO
, h.FSHIPDATE
FROM ARINV01H.dbf h
WHERE
h.FSALESPN = @FSALESPN
AND
h.FSHIPDATE >= @startDate AND h.FSHIPDATE <= @stopDate
UNION ALL
SELECT
v.FINVNO
, v.FSHIPDATE
FROM ARINV01.dbf v
WHERE
v.FSALESPN = @FSALESPN
AND
v.FSHIPDATE >= @startDate AND v.FSHIPDATE <= @stopDate
SELECT
DISTINCT FITEMNO
, SUM(FSHIPQTY)
, SUM(FCOST * FSHIPQTY)
, SUM(FPRICE * FSHIPQTY)
, (SELECT FDESCRIPT FROM ICITM01.dbf i WHERE i.FITEMNO = h.FITEMNO) AS FREALDESC
FROM
(
SELECT
h.FITEMNO
, h.FSHIPQTY
, h.FCOST
, h.FPRICE
FROM ARTRS01H.dbf h
WHERE
h.FINVNO = @FINVNO
UNION
SELECT
v.FITEMNO
, v.FSHIPQTY
, v.FCOST
, v.FPRICE
FROM ARTRS01.dbf v
WHERE
v.FINVNO = @FINVNO
)
GROUP BY FITEMNO "
|
|
|
|
|
Sorry I can't help with the query but I'd assume they are not still using Account Mate? So why not suck all the data into a sql server database and use that for reporting.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The AccountMate for DOS works. The sales rep for them in Dallas sort of dicked them around with the price to upgrade, and raised the price 15K after he paid a visit, so they decided to just stick it to them.
So I made an overlay program for them that performs most of the daily functions for the front office. Hey its income for me, they pay fast.
|
|
|
|
|
Hello all. We use SQL Server 2008r2 and a database failed to start. I want to restore the database, but i need a suggestion.
|
|
|
|
|
RTM - How to Restore a Database Backup[^]
Or give more details re "a database failed to start" - for example what was the error reported?
[EDIT - just spotted this in QA as well - please don't cross post, choose one forum or the other, not both)
|
|
|
|
|