6

I've been scratching my head over this for over a week now and haven't gotten anywhere :( We have an existing legacy DB that I'm trying to model my entities against. The tables are extremely bloated and we do not have enough bandwidth to create new, optimized tables. So I'm having to work with what we already have. However, I do not want to use all the redundant columns that are exposed by the DB. My initial plan was to use Views in my Model but that is looking to be equally hairy with very little documentation around.

Now, what would be the best way to go about creating a Model with just a select few columns? All I need is a bunch of read-only entities; so if there is a way to ignore non-nullable columns from the schema, I'd be all set. I was planning on making use of POCOs else I'd have to create my own mappings I reckon.

UPDATE: By POCOs, I mean I'd like to use the ADO.NET POCO Entity Generator.

1
  • 2
    I'd suggest using NHibernate, create your own POCOs, and mappings with Fluent-NHibernate then only mapping the columns you want. IMO your just asking for trouble building/generating your model off your (legacy) DB schema. Commented Nov 9, 2010 at 21:41

3 Answers 3

2

What about creating views in the DB, and only importing the views into the model?

Sign up to request clarification or add additional context in comments.

4 Comments

Anybody else tried using Views instead of Tables? I'm eager to know your experiences.
Could you elaborate on the suckage? I've used quite a few views in EF and it's worked well...
Hey Steve, here's a question that I posted on the forum yesterday. stackoverflow.com/questions/4129705/…
Steve, after several days of trial and error, I was finally able to create a Model using just Views. I just had to be a little patient I guess :) The EF 4 Recipes book by Tenny and Hirani helped me quite a bit.
1

Well, if you need only a bunch of entities and if they won't change a lot during time, than I would just pick the tables you need, generate the entities with the normal wizard and all collumns, and than delete all not needed collumns manually in the model designer.

4 Comments

The problem with doing that is, we have a lot of non-nullable columns that I really don't want to query and bring data back for. Even though I want a read-only model, EF forces me to use those columns not knowing what to do in cases of inserts/updates.
Also, how would you define relationships?
OK, now I understand the real problem. This I never had. May be you can have a look at blogs.msdn.com/b/dsimmons/archive/2007/11/08/… - but this looks like a lot of handwork...
The fact that the designer does not support this feature kinda defeats the purpose of using EF :(
0

add the table to your EF, and just delete the properties you don't want. it just won't map those DB fields.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.