Entity Framework Rounding - entity-framework-4

One of my entity objects (EF4) has a property that is a decimal. The field in the database is Decimal(18,2)
If I set the value to 30.4777 it only sends 30.47 over to the db in the insert statement (as confirmed by the tracer). Is there a way to get it to send 30.4777 and then just let the database round it off (which it seems happy to otherwise do)?

You can set the Precision and Scale properties of your decimal field yourself. Just right-click the property in the designer, and choose Properties. In the properties window you will find Precision and Scale. Set Scale to 4 and try your queries again.

Related

InfluxDB - batch write multiple points with the same tag

When I write multiple points with the same tag value, it only writes the first point to the database.
Is this a bug or must be different tag values when writing multiple points?
Thank you!
It is a feature, not a bug. You need to create unique points, otherwise non unique points are "deduplicated". See doc https://docs.influxdata.com/influxdb/v1.7/troubleshooting/frequently-asked-questions/#how-does-influxdb-handle-duplicate-points
A point is uniquely identified by the measurement name, tag set, and timestamp. If you submit a new point with the same measurement, tag set, and timestamp as an existing point, the field set becomes the union of the old field set and the new field set, where any ties go to the new field set. This is the intended behavior.

Delphi - How to check if a DataSet has fetched all rows?

As title says, is it possible to check if a DataSet has fetched all it rows?
I am using components that descends from FDQuery.
I need it becouse I was sure my DataSets was fetching all rows everytime, but I noticed that changing the connection.FetchOptions.Mode to fmAll (from fmOnDemand), the time they need to open increases by 1.5 multiplier.
If I understand your q correctly, the documentation answers it:
ProviderEOF is a shortcut for the TFDDataSet.SourceEOF property and allows you >to specify whether all rows are fetched from a DB.
The property is for the TClientDataSet compatibility.
http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.Client.TFDCustomMemTable.ProviderEOF
I am obliged to #Victoria for pointing out that SourceEOF is the better way of checking, see
http://docwiki.embarcadero.com/Libraries/Tokyo/en/FireDAC.Comp.DataSet.TFDDataSet.SourceEOF

Add fields to a clientdataset or access it dynamically?

What's the point in adding fields to TClientDataset if and can do Cds.FieldByName('field').Value?
Is it faster to have the reference?
Is it 'clearer'?
The problem with
DataSet.FieldByName('field').Value
is a performance one. Each time this is executed, it causes a serial search through the fields collection of the dataset to locate the one with the required name. This search is not optimised in any way, for instance by using a binary search or hashing algorithm. So, if there are many fields and/or you are doing this access while iterating the records in the dataset, it can have a significant impact on performance.
That's one reason, but not the only one, to define "persistent" TFields using the Object Inspector. You can obtain a reference to a particular TField by using the symbolic name known to the compiler and this happens once only, at compile time. So yes, it is faster than FieldByName. up to you whether you find it clearer.
Other reasons to use persistent TFields include the ease which which calculated fields can be set up and, more importantly, the fact that the calculated field(s) do not need to be accessed via FieldByName in the OnCalcFields event. The performance hit of using FieldByName versus persistent fields is, of course, multiplied by the number of fields referenced in the OnCalcField event and OnCalcFields is called at least once for each record in the dataset, even if you do not iterate the dataset records in your own code.
The above is true of all TDataSet descendants, not just TClientDataSets.

How to implement a TDataSet-bound combobox with not-in-list values

I need to implement a combobox, which is bound to a TpFIBDataSet (descendant of TDataSet). I've done this several times before. It's not a big thing if it contains only predefined values.
This time, I'd like to have a combobox that accepts custom values entered by the user, also giving the ability to the user to select some predefined value. Newly entered values shall be inserted into some table of the database just before the record the combobox's field belongs to is posted.
The main problem seems to me, that predefined values are internally represented as integer IDs (the combobox I use is TwwDBComboBox from Roy Woll's InfoPower package, as it implements maplist functionality) because the field is a foreign key, while custom values may be nearly everything (only restricted by a mask).
How can I distinguish between an integer ID and integer user-input, for example?
See the set properties of the combobox:
AComboBox.Style := csDropDown;
AComboBox.MapList := True;
I don't request a solution as take this piece of code and be happy. I'm rather looking for some advice by others who might have or had a similar problem.
How can I distinguish between an integer ID and integer user-input, for example?
You go back to the database. Either query directly select count(*) from table where id = ComboBoxId.
Or use the Locate method of the dataset.
Or keep a cache handy in a MyList: TList<Integer> and do a MyList.BinarySearch to see if the item is already in the DB.
Obviously the cache will only work if the DB is single-user, because otherwise you will not be able to keep it up-to-date.
If it is not in the DB, you run the insert query.
After it's inserted you run the default combobox behavior, because now the values is sure to be in the DB.

Delphi TClientDataSet sorting (insert) issue

as far is I know sorting in a ClientDataSet works over the indexDefs.
I can add an indexDef, set the field(s) I want to sort, and over the ixDescending property I can define the direction to sort.
I have a ClientDataSet connected to a dataSource which is the source for a DBGrid.
When I now insert a new record in the ClientDataSet, it's either inserted at the top of the table (ixDescending = false) or at the bottom of the table (ixDescending = true).
But I want a descending order AND new records should be at the top at the table - not at the bottom.
I tried to change the the indexDefs at runtime to achieve this - but without success.
Somebody has an idea how to do this?
When you have inserted a record unless you set values for the indexed fields they are NULL, and sorted accordingly.
I don't know of an elegant solution (although I'm a novice in this area.)
Perhaps there's some way for you to create a temporary boolean field in your ClientDataSet... (Maybe a calculated field?) Suppose you name the new field "NewRecord" and include it in your IndexDef so that it is the most significant sort criteria.
In an .OnCreate event, you set it true (which would be 1 internally?). In an .OnPost event you set it false.
If you don't want to depend on the internal representation of booleans, then you could create a string field and put "ZZZZZZZ" in it. Or an integer field and put MaxInt in it.

Resources