|
I'm using Entity Framework 6 and vb.net 2013 and DBContext.
I have a case when i use reflection to return for an object ( of whatever entity ) , property names and current values :
Dim values = obj.GetType.GetProperties.Where(Function(t2) t2.PropertyType.IsValueType).Select((Function(t3) New With { _
.property = t3.Name, _
.value = t3.GetValue(obj, Nothing) _
})).ToDictionary(Function(x) x.property, Function(y) y.value)
This code is working without problems , but instead of current values that this expression return ( on .value=...) , I need to get the original values for each property.
What changes should I make on my expression ?
Thank you !
|
|
|
|
|
Properties do not contain other values then the current ones.
You may want to try to get these values either sooner, or from a different source.
Read Richards answer
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
modified 10-Aug-15 11:52am.
|
|
|
|
|
Each entry in Entity Framework contains the Original value too.
|
|
|
|
|
So I learned; I was assuming reflection and the PropInfo class
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
You're looking for the DbContext.Entry method[^]:
Dim entry As DbEnttiyEntry(Of YourEntityType) = yourContext.Entry(yourEntity)
Dim currentValues As DbPropertyValues = entry.CurrentValues
Dim originalValues As DbPropertyValues = entry.OriginalValues
Dim databaseValues As DbPropertyValues = entry.GetDatabaseValues()
For Each propertyName As String In currentValues.PropertyNames
Dim current As Object = currentValues(propertyName)
Dim original As Object = originalValues(propertyName)
Dim database As Object = databaseValues(propertyName)
Next
Dim prop As DbPropertyEntry = entry.Property("PropertyName")
Dim current As Object = prop.CurrentValue
Dim original As Object = prop.OriginalValue
Dim prop As DbPropertyEntry(Of YourEntityType, PropertyType) = entry.Property(Function(x) x.PropertyName)
Dim current As PropertyType = prop.CurrentValue
Dim original As PropertyType = prop.OriginalValue
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Sorry friend , but in can't implement your suggestions to my expression. What can I change to my expression because I'm using reflection , and I know only this to get the current value :
.GetValue(obj, Nothing)
How to get the original value.
There's no .GetCurrentValue.
Please look my expression .
Thank you !
|
|
|
|
|
Dim entry As DbEntityEntry = yourContext.Entry(obj)
Dim values = obj.GetType.GetProperties.Where(Function(t2) t2.PropertyType.IsValueType).ToDictionary(Function(p) p.Name, Function(p) New With {
.CurrentValue = entry.CurrentValues(p.Name),
.OriginalValue = entry.OriginalValues(p.Name)
})
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ofc, it is not a classic property; Is the entries' Property property by any chance an indexer than returns a DbPropertyEntry class?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Yes, the DbEntityEntry 's Property function returns a DbPropertyEntry .
DbEntityEntry.Property Method[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Can this be a solution :
obj=context.entry(obj).OriginalValues.ToObject
Dim values = obj.GetType.GetProperties.Where(Function(t2) t2.PropertyType.IsValueType).Select((Function(t3) New With { _
.property = t3.Name, _
.value = t3.GetValue(obj, Nothing) _
})).ToDictionary(Function(x) x.property, Function(y) y.value)
So I can lave my expression unchanged
|
|
|
|
|
Yes, that should work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i need carshowroom mangement system project
|
|
|
|
|
Well you newed to do one of two things:
- Write it yourself.
- Pay someone else to write it for you.
|
|
|
|
|
Well in plain TSQL it was pretty simple to calc the total amount of taxable items.
SELECT
SUM((qty * Price) - (qty * InstantSavings))
FROM ShoppingCart
WHERE SessionID = @SessionID
AND Taxable=1
I've gotten this far, pretty sure I'm on the right track here.
But I don't understand where "totals" come from in my statement. I mean yes I put it there because multiple examples used it, but the examples were just snippets.
I simply don't get it.
Dim pValue As Decimal = 0
Using context As New DBContext()
Dim totals as what?
pValue = _
(
From sc In context.ShoppingCart
Where sc.SessionID = p_sessionID _
And sc.Taxable = True
Group sc By sc.SessionID Into totals()
Select
{
total = totals.Sum(Function(m) (m.Qty * m.Price) - (m.Qty * m.InstantSavings))
}
)
End Using
|
|
|
|
|
I'll go with this, it doesn't work in Linq Pad, but it looks right so far
Dim pValue As Decimal = 0
Using context As New hx5Context()
pValue = _
(
From sc In context.ShoppingCart
Where sc.SessionID = p_sessionID _
And sc.Taxable = True
Select (sc.Qty * sc.Price) - (sc.Qty * sc.InstantSavings)
).DefaultIfEmpty().Sum()
End Using
Return pValue
|
|
|
|
|
pls help !!!
USERID TIMEINOUT CHECKTYPE
120 1/2/2015 04:30:45 AM I
120 1/2/2015 07:50:45 AM O
120 1/2/2015 09:30:45 AM I
120 1/2/2015 02:20:45 PM O
120 1/2/2015 04:10:45 PM I
120 1/2/2015 05:50:45 PM O
135 1/2/2015 07:30:45 AM I
135 1/2/2015 09:40:45 AM O
135 1/2/2015 12:30:45 PM I
135 1/2/2015 02:10:45 PM O
output:
userID date timeIn timeOut
120 1/2/2015 04:30:45 07:50:45
120 1/2/2015 09:30:45 02:20:45
120 1/2/2015 04:10:45 05:50:45
135 1/2/2015 07:30:45 09:40:45
135 1/2/2015 12:30:45 02:10:45
|
|
|
|
|
This article [^]may help...
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
that is the reality output in biometrix...
can you help me??
|
|
|
|
|
|
Doesn't look like a pivot comes from set 1 to 2 - what am I missing?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I wrote this as a substritute for bulk Transfer or Select insert.
It's the same exact table columns, just being copied for archival purposes.
But I get this error, "error updating entity",
really generic. So I think I missed the boat on this one, in terms of how I thought it works.
Using context as new DBContext()
Dim r = _
(
From pi In context.ProductInfo
Where pi.ProductID = p_Product_ID
Select New productBulkTransfer With
{
.PartNumber = pi.PartNumber,
..... 30 more columns
}
).SingleOrDefault()
Dim w As New PRODUCTINFO_RECYCLEBIN With
{
.PartNumber = r.PartNumber,
..... 30 more columns
}
context.ProductInfo_RecycleBin.Add(w)
context.SaveChanges()
End Using
I tried Dim r = ... .ToList()
But the w side, write complained about it in teh context.Add(w)
|
|
|
|
|
It was an error in my DataAccessLayer
I tried to take a shortcut in that model, by inheriting the original model, didn't work
Thought I'd try it, but that was last Monday, and forgot about it.
|
|
|
|
|
Dim CMD3 As New OleDb.OleDbCommand
SQL = "insert into reciptdetails" +
"(Reciptid,Barcode,Itemcount,Itembuyprice,Itemsellprice)" +
"values" +
"(:0 ,:1 ,:2 ,:3 ,:4 )"
CMD3.Connection = Myconnection
CMD3.Transaction = Mytransaction
CMD3.CommandText = SQL
CMD3.Parameters.AddWithValue(":0", reciptid)
CMD3.Parameters.AddWithValue(":1", Barcode)
CMD3.Parameters.AddWithValue(":2", Itemcount)
CMD3.Parameters.AddWithValue(":3", BuyPrice)
CMD3.Parameters.AddWithValue(":4", SellPrice)
CMD3.ExecuteNonQuery()
CMD3.Dispose()
|
|
|
|
|
|
So I'm working on a report using RDLC for a Windows App.
In the report, there are product items, basically a margin report.
So the customer told me that the final totals of cost, price and margin are off, but the line items are correct. OK.
the method loops a list(of invoiceProfit) from a database function
And there are positive, negative and 0 values in the List(of invoiceProfit)
I never manually added numbers in VB before, and have always used SQL Server to do this.
On a small report with a couple of items, its correct, but on a large report with 1000 items, it's off.
Question:
I'm missing something here on this, and I'm not sure what to think.
I think the += just adds numbers, even if the value is negative.
FYI:
I need to get back to the progress bar issue later today, perhaps now. I'll get back to that post later today or tomorrow.
m_totalCost += i.ExtCost
m_totalPrice += i.ExtPrice
m_totalMargin += m_margin
This method produces these values
If (i.ExtCost > 0) Then
m_totalCost = m_totalCost + i.ExtCost
ElseIf (i.ExtCost < 0) Then
m_totalCost = m_totalCost - i.ExtCost
End If
If (i.ExtPrice > 0) Then
m_totalPrice = m_totalPrice + i.ExtPrice
ElseIf (i.ExtPrice < 0) Then
m_totalPrice = m_totalPrice - i.ExtPrice
End If
|
|
|
|