Ignore Columns in Entity Framework

entity-framework

Question

I want to create an EF model from a database, but I don't want to use any of the database's columns since they are only updated on the server and shouldn't be changed by any client applications.

If it makes a difference, the columns are both DateTime; one is nullable and is updated by a trigger, while the other is not nullable and is set using a default value in the table definition.

I suppose I'm searching for something like to Linq2Sql's "Server Generated" option, but I can't locate one.

Can someone please explain how to get around this?

Caveat:

Since a few years ago, I've tried to introduce business object modeling at my place of employment, but each time it has been rejected due to the extra code that has to be manually generated. Because of the designer and code generation, EF is now seen to be a workable answer, therefore any choice that requires manually churning the XML would simply drive the rest of my coworkers away from EF. Therefore, I'm seeking for anything that can be accomplished using either code or a design program.

EDIT:

I suppose what I'm trying to find here is either...

(a) a technique for building the model without EF referencing the store's columns (ssdl) and without trying to modify it in any manner. When I construct the ObjectContext, is there a way to programmatically set the "StoreGeneratedPattern" attribute against the property? (the easy answer is to manually manipulate this in the .ssdl, but this would then be overwritten if I refreshed the model from the database and I cannot go down the route where the .csdl, .msl & .ssdl are hand-cranked).

1
35
4/10/2009 2:22:07 PM

Popular Answer

Can one use Entity Framework to do this? Yes; it's simple. Can you use the Entity Framework designer for this? Unfortunately, it is considerably more difficult.

The fact that the column is present in your EDMX's storage schema (SSDL) is the cause of your issue. The column is only removed from the client schema when it is deleted using the GUI designer; it is not removed from the mapping or the storage schema. However, it's simple enough to go into the EDMX and remove it. After doing so, the entity framework will no longer complain that it is unmapped if you remove it from the mapping in the client schema parts of the EDMX.

Right, the issue is resolved.

Okay, no. The storage schema is discarded and recreated when you update the EDMX from the database using the GUI designer. Your column will thus resume. I'm not aware of any method to instruct the GUI designer to never map a certain column. As a result, you will need to repeat this process each time the GUI designer is updated. Since the EDMX is an XML format, you may do this using an XML transform, LINQ, or another XML tool of your choosing.

29
4/10/2009 2:28:23 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow