Entity Framework Code First: Value cannot be null. Parameter name: value - entity-framework

I found this strange problem with EF and code annotations, on some entities, the save changes throws this exception.

The problem was the DisplayAttribute i had on one of my properties of the model, the Name property, for some reason, can't be assigned to an empty string, the solution was to use the DisplayNameAttribute, which it does support empty strings.

Related

EnumType.STRING ignored by ebean and Play 2

I have a field definition that is set as an enumeration with EnumType.STRING.
Typically, this works nicely, but on two occasions, it has ignored the EnumType attribute and used the ordinal value for the enumeration.
My declaration looks like this:
#Basic(optional=true) #Enumerated(EnumType.STRING)
public StationFormat stationFormat;
I've tried:
Changing the name of the field
It still creates it as an ordinal
Doing a clean compile
Still uses ordinal value
Adding a second field on the same class
Still uses ordinal value
What the heck? I had this happen before, and at some point it magically resolved itself.
-John
I found a solution to this problem, thought I believe the underlying issue is a bug.
To workaround, add the same enum to a DIFFERENT model class. Does not matter which one, and you can delete it immediately afterwards. It will be added correctly to the new class, as well as the existing class will be amended to use the name() value rather than the ordinal.

Error in production only - "The specified value is not an instance of type 'Edm.Int32' Parameter name: value"

I'm receiving the following error:
The specified value is not an instance of type 'Edm.Int32'
Parameter name: value
whilst using the entity framework. I believe this to be a projection problem with enums as previously mentioned in the following question:
Entity framework mapping enum : The specified value is not an instance of type 'Edm.Int32' Parameter name: value
What I'm confused about is, my code works perfectly on my local PC, but as soon as the code is published onto the production server, the server throws those errors. I'm making sure that my reference to the entity framework is being copied to the server (EF 4.4) and nothing else is being cached etc.
Is there anything I need to check on the production server to get this working?
I suppose the difference can be between 32/64 bit machines. Try specifying your enum type
public enum MyEnum : int {... }
Anyway this is similar to
Entity framework mapping enum : The specified value is not an instance of type 'Edm.Int32' Parameter name: value

morphia annotation

I am using mongodb with java and also morphia.
For my usecase i get collection name at run time. So i have a enum of collection names and based on some value i get the corresponding collection name from enum. My entity annotation is as follows
#entity(EnumName.getCollectionName())
But i get the following error
"The value for annotation attribute Entity.value must be a constant expression"
I am actually returning a constant expression only. Could anyone let me know what the issue is.
You can't use some something dynamic within annotations as those are "compile" time features which can't be changed afterwards. So you can only handle constants which you declared there, Enums and Classes. For this a smart compiler may be able to find out that you handle something which may never change, but most wont and will simply error as soon as they see that you're trying asign some function value to an annotation property.
I don't really understand what you're trying to do, but it somehow looks like you try to use one "generic" entity class for several concrete entities. I think this is really bad design.
If you can tell more details, we may be able to give you a proper solution for your problem.
If you simply don't know what Class you have to operate with at runtime, try this.
Declare your concrete entities and fill your enum with those Classes. At Runtime you can do Datastore.find(Enum.YOURCLASS) and morphia will query your appropriate class.

Strongly typed ViewModel contains unexpected null value

I have a case that is very similar to this, but following the advice in the answers does not solve my problem.
I have a ViewModel in an MVC 2 application that contains another class. I have a controller that contains a strongly typed create method:
[Authorize]
[HttpPost]
public ActionResult Create(AIViewModel ai)
{
}
When I look at the ModelState when I enter the Create method, the data indicates that the simple properties that are present within the AIViewModel class are bound correctly, while the complex type that is in there fails with the following error message:
"The parameter conversion from type 'System.String' to type 'xyz' failed because no type converter can convert between these types."
If I look at the value that it tries to bind, it has indeed the System.String type and value "Create". Anybody has a clue on what I could be doing wrong?
UPDATE: I have found the problem: The property is called Action, which somehow fools the the modelbinder. Renaming the property solved the issue.

iPhone Coredata saving error

I'm trying to create core data application.
Some times when trying to save data, i'm seeing following error:
Error: NSInvalidArgumentException,
Reason: * -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]!,
Description: * -_referenceData64 only defined for abstract class. Define -[NSTemporaryObjectID_default _referenceData64]!
I didn't understand why this error is coming and how to avoid it. Can some one help me please.
Edit: The original answer below is technically correct but doesn't accurately describe the true source of the error. The runtime can't find the correct attribute but the reason it can't find it is because the entity exist in another managed object context. The OP probably never had a _referenceData64 attribute for any of his entities.
See: http://www.cocoadev.com/index.pl?TemporaryObjectIdsDoNotRespondToReferenceData
Original Answer:
You have a class that has an attribute _referenceData64. In the data model, that class is marked as "abstract'. Select the entity in data model editor and check the box below that says "abstract". If it is checked, then that is your problem.
An abstract entity is never instantiated. Unless is has a subclass, you can't actually set its attributes to any value. Abstract entities just exist to provide templates for subclasses.