AutoMapper is not mapping my byte array fields - asp.net-mvc

I have a pretty straightforward POCO that contains a property called Image of type byte[]. I'm finding that if this field is set to null, and the Entity Framework object I'm mapping to already has a value for the Image property, the EF object value is not being set to null after I call Mapper.Map.
Is there something specific I should be doing to force AutoMapper to do this, or should I be doing this manually?
Using version 2.2.1 of AutoMapper.
Thanks,
Gary

I realized I was actually on a pre-release version of 2.2.1. After upgrading to the latest version this issue appears to have disappeared. If anyone else finds this happening you may want to check this as a possible solution.

Try using the AllowNullCollections configuration option:
Mapper.Configuration.AllowNullCollections = true;

Related

Spring data neo4j 3.0.1 properties of type Object not stored anymore

We are in the process to migrating to neo4j 2 and thus SDN 3.0.1.
We have hit a problem with classes that have properties of type Object. It looks like these are not saved in the database anymore. When I changed one of those properties to String for instance, that particular property was saved.
We are using Object type sometimes because we do not know whether the value will become a String, int, long, or whatever type that is supported in neo4j.
So, is this a bug, or a new restriction, or maybe do I need to register some sort of converter?
Turns out to be that SDN 3.0.1 is incompatible with Spring 4, I created an issues for it: jira.spring.io/browse/DATAGRAPH-458

How does Breeze handle database column defaults?

I can't find any info about this in the documentation, so I will ask here. How does breeze handle database column defaults? I have required columns in my database, but there are also default static values supplied for these in the database column definitions. Normally, I can insert null into these columns, and the new records will get the default. However, breeze doesn't seem to be aware of database column defaults, and the entities that have null in these columns fail validation on saving.
Thanks,
Mathias
Try editing the edmx xml by adding StoreGeneratedPattern = "Computed" attribute to the column with default value in the DB.
Edit:
Actually, before doing editing the xml, try setting the StoreGeneratedPattern property to Computed in the model editor itself.
Update:
This was fixed in Breeze 1.4.6 ( or later), available now.
Original Post:
There is currently in a bug in Breeze that should be fixed in the next release, out in about week. When this fix gets in then breeze will honor any defaultValues it finds in the EntityFramework data model.
One problem though is while it is easy to get 'defaultValues' into a Model First Entity Framework model via the properties editor, it's actually difficult to get it into a Code First EF model, unless you use fluent configuration. Unfortunately, EF ignores the [DefaultValue] attribute when constructing Code First model metadata.
One workaround that you can use now is to poke the 'defaultValue' directly onto any dataProperty. Something like:
var customerType = myEntityManager.metadataStore.getEntityType("Customer");
var fooProperty = customerType.getProperty("foo");
fooProperty.defaultValue = 123;

Default Constraints in Entity Framework

Very simple question that NO ONE has directly answered. Is there no way to insert an entity using EF4 that uses the database default constraint and yet allows that field to be updated later? There doesn't seem to be. When I have a date property for instance and want it to use the database default, I seem to have two options:
1) Set the "StoreGeneratedPattern" to "Computed" or "Identity" which prevents me from updating it later.
2) Ignore the database default entirely and set the default value myself.
Neither one of these options will work for me, and this seems to be a huge weakness with the framework. Any ideas? Is this bug resolved in EF5.
No.
Relevant UserVoice suggestion.
You could extend the generated class and set the default values in the constructor of the patial class.
public partial MyEntityClass MyEntity
{
public MyEntityClass()
{
this.DefaultValueProperty = defaultValue;
}
}

Entity Framework, Oracle, DevArt, Context#ExecuteStoreQuery: System.Int32 constructed as System.Double?

I have an Entity-class having a Property of type Int32: on generating DDL using DevArt for ORACLE a NUMBER(10) column is generated. Reading and writing instances works flawlessly.
However, on fetching instances of this Entity-class sending a custom query to ExecuteStoreQuery on the ObjectContext this Property seems to be returned as System.Double, as such constructing the instances fails.
Can I hint DevArt to construct System.Int32?
Thank you.
Bart
The reason is the fact that OracleDataReader, which is used in the ExecuteStoreQuery method, has type mapping different from the one used in the Entity Framework provider.
I recommend you to use NumberMappings, I suppose you will need to map Number(10) to Int32: Number Mappings=((NUMBER,10,10,System.Int32). These changes should be persisted to the model connection string (they are duplicating the default EF mapping rules, it is necessary for the OracleDataReader from ExecuteStoreQuery).
Please let us know if the problem persists.

How to store a file in the database with Grails

I need to store a file in the database using Grails. So, do you know how I can do that? Which data type should I use in the domain class (byte[] might be a solution)?
See Chapter on Uploading Files in the Grails User Guide. It is also possible to use a java.sql.Blob as type for the binary content (which would be preferable when dealing with huge files).
alternatively, store the file on disk, and store the path to it in the database. it is generally faster to access that file on disk than in a db. but of course, that really just depends on your needs in the app. But be aware of this alternative.
You can force the domain object to use a specific type when updating or generating the database with column mappings:
byte[] orgFile
static mapping = {
columns {
orgFile type:'blob'
}
}
This has worked for me so far ;)
I have had the same problem. All I needed to do was to go to the database (Oracle) and change the column type from RAW to Blob. (Actually I had to remove the column and then to create a new one).
I was never able to find out how to use a "java.sql.Blob" as suggested above. I found this this (converting from bytes to Blob), but it seemed a bit complicated.
I recently used byte[] in a domain class for storing file, it was working fine until i moved my application from "HSQLDB" to "Oracle express".
On Oracle, byte[] was mapped to a raw object instead of blob... (not sure of what was exactly wrong) and I finally solve the problem by using a java.sql.blob

Resources