TinyInt as datatype for enum - codefluent

I have a lot of enumerations as properties in my codefluent model. Codefluent uses an int as datatype to store this. In all cases a TinyInt would suffice. I can set the datatype to int16. How can i reduce it even further to set it to TinyInt.
PS Maybe setting it to INT16 by default would be better for enums.

The attribute enumTypeName allows to define the underlying CLR full type name. The DbType is inferred from the CLR type name. If you set System.Int16, the DbType will also be Int16:
<cf:enumeration name="Gender" enumTypeName="System.Int16">
<cf:enumerationValue name="Unspecified" />
<cf:enumerationValue name="Male" />
<cf:enumerationValue name="Female" />
</cf:enumeration>
You can set the value of this attribute in the graphical interface:

Related

Swift core data: why do I need to unwrap when setting optional attribute values?

I have a core data model that contains mainly optional attributes. I assumed then that I would not need to unwrap the values that I am assigning to these optional attributes. e.g. I thought I would be able to do:
myEntity.gravity = currentOrder.gravity
(myEntity.gravity being optional)
However, Swift still requires me to unwrap currentOrder.gravity. I would have thought given that the variable I am assigning to is optional that I would not need to unwrap this.
Update:
Here is the definition of one of the core data entities I am describing:
<attribute name="percentComplete" optional="YES" attributeType="Float" defaultValueString="0.0" usesScalarValueType="YES"/>
The entity itself:
<entity name="AircraftMeasurementsCD" representedClassName="AircraftMeasurementsCD" syncable="YES" codeGenerationType="class">
It seems you're equivocating on the word "optional".
The word "optional" in the attribute description optional="YES" is not the same as, and has nothing to do with, the Swift Optional enum type.
The former is merely the ordinary English word "optional", meaning "not required" — for a particular entity, there might or might not be a value for this attribute, which is a Float, but even if there isn't, it's a valid entity. Nothing in the story says that this attribute's type is Optional<Float>. Its type is Float. And you can't assign a Swift Optional where its wrapped type is expected; you have to unwrap it.
Indeed, this point is made very explicitly by the documentation:
Optional attributes aren’t required to have a value when saved to the persistent store. Attributes are optional by default.
Core Data optionals aren’t the same as Swift optionals. [My italics.]

Passing classes in with Slots to vue components

I have a vue component
<Student></Student>
I want to change the style based on if they are an undergrad or postgrad.
I know I can pass in a prop and use this value to assign a dynamic class or use it in a computed prop.
<Student type="'postGrad'"></Student>
But can I do this with slots and assign a class or is there a better way to use props to achieve this?
<Student>
<slot name="type">PostGrad/slot>
</Student>
I have always used props but feel I could be missing a good technique with slots.
Just try to add class
<Student class="myClass">
<slot name="type">PostGrad/slot>
</Student>

How does Core Data codegen decide whether to make a property optional?

I am working with Xcode 10 + Swift 4.2 on macOS 10.13.6 High Sierra. I have created a data model and I am letting Core Data automatically generate classes for the data model entities. For the most part this works as expected. However, I cannot figure out how to predict whether some properties in the generated classes are going to be Optional types; it does not appear to depend on whether the corresponding attributes were declared as "Optional" (i.e. "Optional" check box is checked in the description of the attribute). Can someone help me figure out how Xcode figures out whether to make a class property optional or not?
Here is a small example which I've derived from my project. I just replaced the project-specific names with made-up names, but everything else is the same. First here is an extract from the data model for the description of the Foo entity:
<entity name="Foo" representedClassName="Foo" parentEntity="FooParent" syncable="YES" codeGenerationType="class">
<attribute name="v1" attributeType="Date" usesScalarValueType="NO" syncable="YES"/>
<attribute name="v2" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
<attribute name="v3" optional="YES" attributeType="Boolean" usesScalarValueType="YES" syncable="YES"/>
<attribute name="v4" optional="YES" attributeType="UUID" usesScalarValueType="NO" syncable="YES"/>
<attribute name="v5" optional="YES" attributeType="String" syncable="YES"/>
<relationship name="v6" toMany="YES" deletionRule="Nullify" destinationEntity="Bar"
inverseName="baz" inverseEntity="Bar" syncable="YES"/>
</entity>
As you can see, v1, v2, and v6 are not declared optional in the data model, while v3, v4, and v5 are declared optional. Here is the code that was generated, which I found in Foo+CoreDataProperties.swift somewhere under the Xcode/DerivedData folder for my project.
extension Foo {
#nonobjc public class func fetchRequest() -> NSFetchRequest<Foo> {
return NSFetchRequest<Foo>(entityName: "Foo")
}
#NSManaged public var v1: Date?
#NSManaged public var v2: Bool
#NSManaged public var v3: Bool
#NSManaged public var v4: UUID?
#NSManaged public var v5: String?
#NSManaged public var v6: NSSet?
}
As you can see v2 and v3 are not optional, while v1, v4, v5, and v6 are optional, and that's a different assignment of optional/non-optional than what was seen in the data model.
Can someone help me understand how Core Data decides whether a generated class property should be optional or non-optional?
On the one hand, I find myself writing v!.something where I would hope that I can write v.something because v is non-optional in the data model, and therefore there will certainly be some value present (assuming Core Data is enforcing the non-optional attribute).
And on the other hand, I want to write let v = v { ... } for a property v which is optional in the data model, so there might or might not be a value present. Xcode is giving me an error about that construct, but I can't omit a test -- I already know that some instances of v will be absent. Attempting to work around by writing if v != nil { v! } fails -- Xcode gives an error about not being able to unwrap a non-optional value (and also a warning about comparing a non-optional to nil).
Thanks in advance for any light you can shed on this.
EDIT: For the last bit about a non-optional property corresponding to an optional attribute, I see that I can just omit the ! and write if v != nil { v } -- of course the warning about comparing non-optional to nil is still there, but the error goes away. So that's a workaround.
Core Data is still rooted in Objective-C. So the primitives (bool, int, float, etc.) will be non-optionals, and the objects will be optionals.
Some data can be either an object or a primitive. For example, someone's age could be a NSNumber or a NSInteger. If you prefer that such a variable be backed by a primitive, then you can check the scalar box for the property in your model.
I think you could look at attribute tab, there's optional="YES". It decided if that property is optional or not. You could changes by unchecked optional in Data Model insepector

Why does Realm use RealmOptional<Int> rather than Int? for optional properties?

Realm's documentation on optional properties states:
String, NSDate, and NSData properties can be declared as optional or non-optional using the standard Swift syntax. Optional numeric types are declared using RealmOptional.
Why do numeric types use the non-standard RealmOptional rather than Swift's built-in optional syntax?
Realm model classes automatically implement getters and setters for your persisted properties that access the underlying database data. In order to provide these getters and setters, your properties must be declared with the dynamic modifier. This modifier asks Swift to dynamically dispatch accesses to the properties via getters and setters rather than directly accessing the member at compile time. The dynamic modifier comes with a significant limitation: it is only supported for types that can be represented in Objective-C. This is because Swift's dynamic dispatch is built on top of the Objective-C runtime. It is this limitation that prevents Int? from being directly supported by Realm.
You may wonder how String?, NSData?, and NSDate? are supported given this limitation. The answer is that they have natural equivalents in Objective-C, namely nullable NSString *, nullable NSData *, and nullable NSDate *. No such equivalents exist for Swift's numeric types.

EF6 Contains Query Casting

Edmx file has
<Property Name="SomePrimaryKeyID" Type="bigint" />
Corresponding object's property is
<Property Type="Int64" Name="SomePrimaryKeyID" Nullable="false" />
Query:
long[] ids = new long[]{1234567,1234568};
var results = context.SomeEntities.Where(x=> ids.Contains(x.SomePrimaryKeyID)).ToList();
When I use contains, EF generated query has explicit casting such as
... WHERE SomePrimaryKeyID IN (CAST (1234567 AS BIGINT),CAST (1234568 AS BIGINT))
Since long corresponds to bigint, I don't see a need for cast. Is there a way I can avoid this cast?
For literal integral values the default type in the SQL Server is int. Because of that in your example the literal values would have to be always cast (they would be of type 'int' if there was no explicit cast) to match the type of SomePrimaryKeyID (which is big int). If the explicit case was missing Sql Server would have to do an implicit cast which actually might be more expensive since it would have to first reason about the type of the SomePrimaryKeyID to know what to cast the literal numbers to.