Subsonic SimpleRepository Nullable string problem - string

I am having a problem with subsonic simplerepository.
I have a users class and it has some optional fields.these optional fields are of type string. As soon
as I try to persist my object , if the optional fields are null , an exception is being thrown
I know string is already of type nullable so i cannot do something like nullable and string?
so what should i do in this case ?
Another option that I have at this point of time is , before persisting the object, check if the optional attributes are null
if they are null, assign them some dummy data. for example "abracadabra". now whenever i am populating the objects
back from the database i check if optional attributes have this value.
if they have this value I make the optional attributes empty in my class.
ah! one more thing, please !
can i use ActiveRecord for winforms?

Add the [SubSonicNullString] attribute.

Related

ProtoBuf - Can a field support two possible datatypes?

is it possible for one field in protobuf to support/accept a string or an array of string.
This is my message:
message MessageA {
string fieldId =1;
string method = 2;
google.protobuf.Any value =3;
}
The reason for it being dynamic is because an array of string or a simple string can be the input. There are separate methods on what will happen if the payload is string[] or string.
Right now, I'm using any but I'm not sure what to do in the any file. I've read that oneof does not support array data types thats why I'm trying to make it work with any.
Here is the error message when I try to put a repeated inside a oneof:
No, basically. The main way of doing this would be to have two inner-types - one with a single-valued member, one with a repeated member, and have a oneof that covers the two inner-types. Or perhaps simpler: just have a repeated and separately have an enum, boolean, or other indicator to choose between the two possible meanings (so you can tell between "an array, that happened to have exactly one item" vs "the single value").
For anyone that might have the same problem as me, you can use google.protobuf.Value. There would be an additional object but it can be transformed using UsePipe so it shouldn't be a problem.
Here is the documentation: https://developers.google.com/protocol-buffers/docs/reference/google.protobuf#google.protobuf.Value

Mongoose schema method not working after select paramter

I have a mongoose model with a method that checks a field and dynamically returns a value, and is called in an HTML template.
This gave me a problem when cleaning up routes to only select fields needed on the page.
After including the select parameter as in Model.find({}, 'select parameter', cb..., this schema method started failing, despite including in the select parameter the property this schema method checks.
Whats up with this, is there a way around it?
The schema method is defined inside thingSchema.methods: { ... ...
and looks for this.thing.length
which is included in the select parameter 'thing, otherThing, thingyThing, thingestThing'
and is called in the html template like thing.getThing(), which will throw error can't find prop length of undefined.
It turns out there is a problem with the string type for the select parameter.
Use the object type instead: {thing:1,otherThing:1,things:1}.

Mapping IQueryable class from Automapper

Does Automapper works with IQueryable?
I have 2 Query
IQueryable<V_ImageUpload> Query1;
IQueryable<V_ImageUpload> Query2;
Mapper.CreateMap<IQueryable<V_ImageUpload_WithReceiptBackup>, IQueryable<V_ImageUpload>>();
Query1 = Mapper.Map<IQueryable<V_ImageUpload_WithReceiptBackup>, IQueryable<V_ImageUpload>>(Query2);
Exception occured is:
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary
I've not used AutoMapper (so this was an excuse to try it out!), but there are queryable extensions available. Both your queryables are of the same type, so I'm not exactly sure what you are trying to achieve, but perhaps something like this is what you want, which takes an IQueryable<V_ImageUpload_WithReceiptBackup> and converts it to an IQueryable<V_ImageUpload>:
IQueryable<V_ImageUpload_WithReceiptBackup> query1;
IQueryable<V_ImageUpload> query2;
// Only map the actual type, not the queryable types
Mapper.CreateMap<V_ImageUpload_WithReceiptBackup, V_ImageUpload>();
query2 = query1.Project().To<V_ImageUpload>();
The .Project().To<V_ImageUpload>() keeps it as IQueryable, while Mapper.Map would end up with a List/IEnumerable. I only tested this out with LINQ to Objects, but hopefully it works with Entity Framework, or whatever you are using.

Optional Parameters from CodeParameter

I am using a T4 to create my interface, however the only issue I am having is if my methods have optional parameters, I am not adding them to the interface.
I'm using EnvDTE to get the information and I have the CodeParameter, but do not see a way to tell it parameter has optional value.
Anyway to tell if the parameter has an optional value?
Try using CodeParameter2 instead. It has a ParameterKind property, which can be set to vsCMParameterKindOptional, and a DefaultValue property.

optional parameters for immutable classes

I am not sure whether this is the right forum to ask this question, but it refers to code, so I am asking here.
In the book "Groovy in action", section 7.1.4 (named parameters), the author says that usage of named params "crops up frequently in creating immutable classes that have some parameters that are optional".
What has immutability of the class got to do with optional parameters? I thought these 2 topics were completely orthogonal.
crops up frequently in creating immutable classes that have some parameters that are optional
the sentence above is a bit blurry as there is no such thing as "class parameters", i can only assume it relates to method/constructor parameters.
when we're talking about constructors, Groovy's named parameters make sense when its about optional parameters:
#groovy.transform.Immutable
class Person {
String firstName
String lastName
Integer age
}
def p = new Person(age: 42, lastName: 'Doe')
The above example shows how to create an immutable Person instance. The firstName is not provided as named parameter, it's optional. In fact, with named parameters it's possible to specify any parameter combo when making the constructor call without actually having to implement constructors for all combinations.
There is also the possibility of using named parameters in instance/static method calls, as shown in this blog post by Mr. Haki.
The key to that statement is that if you're dealing with an immutable class, the implication is that you have only one chance to set state - in a constructor. Normally you'd be able to manipulate an (mutable) object via setters, one-at-a-time, to build up the desired state. For an immutable, you'd have to create a ctor for every possible set of instantiation states instead, if a facility like optional params were not available. For a class with many fields, this could get messy.

Resources