Tagged: EF

Interesting Web Dev Things 21 Oct 13

Advertisements

System.Data.Entity.Edm.EdmEntityType has no key defined

Things to check if you get the “System.Data.Entity.Edm.EdmEntityType has no key defined” error

1) Have you set the primary key in the database

2) Explicitly add a property for the key field name with the data annotation [Key]
e.g.

[Key]
public int ProductId {get; set;}

3) Ensure you have the getter/setter defined for your model for the mapping to occur

N-Tier Patterns Links

Anti-Pattern #1: Tight Coupling
Anti-Pattern #2: Assuming Static Requirements
Anti-Pattern #3: Mishandled Concurrency
Anti-Pattern #4: Stateful Services
Anti-Pattern #5: Two Tiers Pretending to be Three
Anti-Pattern #6: Undervaluing Simplicity

DTO’s, Contract Amendment Pattern, Service Contract and Design Guidelines for Service Contracts, Dealing with Breaking Changes

The specified parameter ‘list’ of type ‘….’ is not valid. Only scalar parameters (‘such as Int32, String, and Guid’) are supported.

I recently migrated over to .Net 4.0 to get access to the L2E Contains support (Where In decomposition). Whilst MSDN does suggest that it is supported in Entity Framework 4.0, I found that it doesn’t seem to work in pre-compiled queries. It seems that pre-compiled queries can only accept scalar parameters

“The arguments to a compiled query all need to be scalars because they all become parameters to the generated database command and these can only be scalars.”

In the end I resorted to a dynamic query using expression trees.

EF refresh model problem

I was just going back through my list of “lessons learned” and recall this one stumping me for a while.

Basically I was having a problem where deletion of rows in a table weren’t removing the associated rows via the foreign key constants as I was expecting. So I go back to the database set the deletion property to cascade and update the entity model. Still doesn’t work

A closer look at the edmx file shows that the changes aren’t carried through all the mappings (just the database mapping side). So manually add the new line to the foreign key properties and it works! I hope refresh is fixed in 4.0