映射模型到数据库设计 - MVC

时间:2014-09-21 01:00:58

标签: asp.net-mvc asp.net-mvc-4 entity-framework-5

我是MVC的新手并且正在学习一些教程。我得到了Code First设计的概念和/或如何将数据库实体(已经存在)映射到模型。但我现在的情况是,我已经设计了我的模型和数据库设计(关系),因为我在WCF中做了一个项目。我的数据库设计并没有完全反映我的模型设计(我从未想过我会很快在MVC中做些什么)。所以请帮助我,我真的需要从现有数据库重新创建我的模型吗?我可以使用EntityTypeConfiguration类(以某种方式)将模型映射到数据库设计吗? 我的观点(个人而言,虽然开放)但我不想再次重建我的模型。还有其他办法吗?

P.S。目前我正在使用ADO.NET存储过程调用从数据库中检索数据,其中存储过程'加入'所需的表并给出结果。
任何帮助非常感谢。 感谢

编辑: 与数据库设计不同的类的一个示例:

enter image description here

我的实体类设计:

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

1 个答案:

答案 0 :(得分:0)

找到解决方案。 经过几天的挖掘后找到了解决方案:

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

&#39;将实体类型的属性映射到数据库中的多个表(实体拆分)&#39;

谢谢你们的帮助。