|
satc wrote: I have a large string that when is saved to VarChar(MAX) field , the size is 250 bytes.
250 bytes isn't a large string; varchar(max) can store up to 4,294,967,296 characters.
Compression typically works best on data with lots of repetitions. If every character of your string is a different character, the compressed data will always be larger than the input. If your string was just the same character repeated 250 times, the compressed data would be much smaller.
There's no need for a third-party library to compress strings in .NET - the System.IO.Compression namespace will do the job for you:
http://stackoverflow.com/a/2118959/124386[^]
public static byte[] CompressString(string str)
{
using (var output = new MemoryStream())
using (var gzip = new DeflateStream(output, CompressionMode.Compress))
using (var writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
{
writer.Write(str);
return output.ToArray();
}
}
public static string DecompressString(byte[] input)
{
using (var inputStream = new MemoryStream(input))
using (var gzip = new DeflateStream(inputStream, CompressionMode.Decompress))
using (var reader = new StreamReader(gzip, System.Text.Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yes , I know that 250 bytes is not a large string. But I have just tested with this string.
On this string the are a lot's of characters that repeats.
The library that I mention is based on the Net compression library but has some more functions. So the result is the same.
Why the compressed string has a larger size ?
|
|
|
|
|
Is the library you're using compressing the string, or creating a zip file? The overhead of a zip file would likely outweigh the benefits for such a small string.
Have you tried compressing your string using just the built-in methods?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The library can create a zip file and also can compress a string. In this case I've used the library to compress the string.
|
|
|
|
|
But have you tried the built-in methods to see if there's any difference in the output size?
Can you post the string you're trying to compress?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Using your function posted before :
public static byte[] CompressString(string str)
{
using (var output = new MemoryStream())
using (var gzip = new DeflateStream(output, CompressionMode.Compress))
using (var writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
{
writer.Write(str);
return output.ToArray();
}
}
I always get a 0 length array.
Is there any error to this function ?
I have tried with different strings , and always I get a 0 length array.
Thank you !
|
|
|
|
|
Sorry, it looks like the DeflateStream doesn't flush properly until you call Dispose . Try changing the function to:
public static byte[] CompressString(string str)
{
using (var output = new MemoryStream())
{
using (var gzip = new DeflateStream(output, CompressionMode.Compress))
using (var writer = new StreamWriter(gzip, System.Text.Encoding.UTF8))
{
writer.Write(str);
}
return output.ToArray();
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hello my friends ! Sorry for this simple question that I post here.
Well, I need to update data in one Reoport Viewer. The problem is that its impossible. The only way that I found was just close the form and open it again. There is one code that I can use to update the report? One simple command or code line, if its possible? Thank you everybody, from Brasil !
|
|
|
|
|
Did you try the RefreshReport method[^]?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi, Richard !
Yes, I tried this and the Update method too. But, not work.
Thanks!
Lárimer
|
|
|
|
|
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
|
|
|
|