Avais
Avais

Reputation: 119

Mapping Model to Database Design - MVC

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...
    }

Upvotes: 0

Views: 3823

Answers (1)

Avais
Avais

Reputation: 119

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.

Upvotes: 1

Related Questions