Learning Entity Framework [modified]
-
Hello everybody. I'm asking for help in learning how to use this new MS product. As a developer of mainly LOB apps, I'm always interested in new ways to avoid the boilerplate code that's common when dealing with data layers. Except that after a few days dealing with EF4 I'm not finding any improvement, it seems to stomp on my feet on every basic real world requirement. I read about model-first design and I found it a step in the right direction. So I built a simple model: Customer <-> Order <-> Item Built the associations and generated the MSSQL database. Nice! Oops, it creates all fields as varchars. Right, I didn't tell him that the field OrderDate is a Date, so I change that and regenerate the script. Mmm? Drop table? I have to generate the ALTERs by hand? Google and find the (beta) tools[^] to update my database automatically. This works, though I have to admit I only tried simple changes. Fire up some tutorials. Learn about the different related windows in VS2010. Next lesson: entity splitting. I follow the tutorials and try to create a separate CustomerAddress entity, which I later merge into Customer. Seems to work, save and generate the DB scripts: the CustomerAddress entity is gone from the DB and the fields are merged into Customer, even without using the ALTER script power pack. WTF? Ok, maybe entity splitting isn't so useful in real life, I can live with two separate entities and manual joins. Let's get back to studying the model. I see that by default it generates properties for the entity keys. I don't need them, recreate the entities to delete them (I didn't find any other obvious way). Regenerate the DB. I notice that the FK columns are generated with a standard name: <ENTITYNAME>_<KEYNAME>, in my case the ugly Customer_CustomerId. I decide to change it into my familiar id_customer, and fail to find a suitable command. The properties window shows the name as readonly, the Mapping Details window doesn't let me specify another name, F2 does not do anything. It's readonly. So I take an axe and drill down into the edmx XML. Find/Replace seems to work, the model now seems ready to kick off a simple application and test queries. I only need to generate the DB... and it reverts my manual changes! Fields name are back to Customer_CustomerId! WTH