0

I am new to MVC and been going through some tutorials. I got the concept of Code First design and/or how to map database entities(already existing) to Models. But the scenario I am having is, I already have my models designed and database designed (relational) as I was doing a project in WCF. My database design does not exactly reflect my model design (I never thought I would be doing something in MVC this soon). So please help me out, do I really need to re create my models from existing database ? Can I use EntityTypeConfiguration class(somehow) to map the models to database design? My point of view (personally, open minded though) I do not want to recreate my model again. Is there any other way?

P.S. Currently I am using ADO.NET stored proc calls to retrieve data from database where the stored procs 'JOINS' the required tables and gives me the result.
Any help much much appreciated. Thanks

Edit: One example of class different than the Database design:

enter image description here

My Class design for the entity:

public class Offer
{
    private int _offerID;
    private string _offerLogo;
    private byte[] _offerLogoBytes;
    private string _offerHeading;
    private string _offerDescription;
    private string _offerInStore;
    private string _offerOnline;
    private DateTime _offerStartDate;
    private DateTime? _offerEndDate;
    private IList<Product> _itemsOnSale;
    private string _offerType;
    private decimal _offerDiscountValue;
    private string _offerT_and_C;
    private bool isPersonalised;
    private List<int> _ageRanges;
    private int _genderSection;

    public Offer()
    {
        ItemsOnSale = new List<Product>();
        AgeRange = new List<int>();
    }
    .
    .
    other methods and public properties...
    }
2
  • Look into Database First. This will automatically generate entity classes for you based on an existing database. Commented Sep 22, 2014 at 2:58
  • Three question marks. The answers are: maybe, yes, maybe. In other words: we can't answer your question. Show one typical example of a class where the database design differs, so we can try to make it fit. Commented Sep 22, 2014 at 8:55

1 Answer 1

1

Found the solution. After days of digging around found the solution on:

http://msdn.microsoft.com/en-gb/data/jj591617.aspx

'Mapping Properties of an Entity Type to Multiple Tables in the Database (Entity Splitting)'

Thank you guys for the help.

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

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.