Transformable and NSKeyedUnarchiveFromData
This warning appears because apple will remove it in future release because it's not secure by default. Here is thread on Apple forum.
You should use NSSecureUnarchiveFromData instead of that.
Storing and Managing unit of measurements
I think you should have a better abstraction than a String; it's little more than a primitive.
I'd write a Units class that would parse and store those Strings from the database and allow you to compare them easily.
public class Units {
private final String name;
// constructors, equals, hashCode, toString and other operations here
}
It might also be useful to have categories of Units. (You can measure pressure a lot of ways.) British and international units can describe the same thing.
You might also have categories based on physical quantities (e.g. force, mass, charge, time, etc.)
How to model attribute units in a database design?
Interesting question...
There are two obvious routes:
id load_kW fuel_consumption_tonnes
--------------------------------------------------
1 1154 89.4
2 1199 54.2
This is easy for humans to read, and fairly logical. However, if some readings are in "kilos", others in "tonnes", you have to convert those readings to fit into the "readings" table; this process MUST be "lossless", and idempotent. For instance, a reading of "89403 kilos" is not "89.4 tonnes", even though the business may choose to round from kilos to tonnes for convenience. There are usually some counter-intuitive rounding things that happen...
If that's the case, you could change the schema:
id load load_unit fuel_consumption fuel_consumption_unit
--------------------------------------------------
1 1154 kW 89403 kg
2 1199 kW 54.2 t
With a "unit" table, if you need it:
unit_id unit_name
--------------------
kg kilogramme
t Tonne
However, this model is open to human failure - it would be easy to change the "load_unit" column without modifying the "load" column, thus breaking the data. There's nothing you can really do to your data model to avoid this. It also makes common queries fairly tricky: imagine trying to retrieve the total of "load" in a consistent unit of measurement.
I would recommend that in this case, you have two tables: "raw_readings", with the original data in the format above, and "normalized_readings", which you populate by converting all the readings to a consistent unit of measurement.
Unit of Work Pattern And Updating Entity Collection Properties
Thanks to SOfanatic's comment, the problem has solved now.
I've updated my GenericRepository's BuildQuery method to reflect SOfanatic's suggestion and it worked.
Here is the updated BuildQuery method:
internal virtual IQueryable<TEntity> BuildQuery(Expression<Func<TEntity,bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
{
IQueryable<TEntity> query = this.context.IsReadOnly ? dbSet.AsNoTracking() : dbSet;
foreach (var include in includeProperties.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
query = query.Include(include);
}
if (filter != null)
query = query.Where(filter);
if (orderBy != null)
return orderBy(query);
return query;
}
DbContext.IsReadOnly is a custom property I added to my DbContext implementation. That way if I want to load entities in a kind of "read-only" mode (only selects) I disable lazy loading, proxy generation and change tracking so it increases EF performance a bit.
Related Topics
Conform to Protocol and Keep Property Private
Swfitui List Make Scrolling Disabled
Firebase References Undeclared
Formsheet iOS 8 Constraints Are Same as Iphones Constraints
String Comparison in Swift Is Not Transitive
Swift Extension Storage for Protocols
Swift Combine Publishers VS Completion Handler and When to Cancel
How to Do a Long Press in Swift
Typecast Unsafemutablepointer<Void> to Unsafemutablepointer<#Struct Type#>
Appending Text to Nstextview in Swift 3
How to Rotate an Arkit 4X4 Matrix Around Y Using Apple's Simd Library
(Appkit) Tab Insertion Inside of Nstextblock
Building an Nsoutline View with Check Marks
Bit Field Larger Than 64 Shifts in Swift