[MVC] 筆記01-01 Creating Data Model Classes with Entity Framework

摘要:[MVC] 筆記一

在Models資料夾中,新增檔案類型為ADO.NET Entity Data Model的檔

在Models資料夾中,新增BURespository,使繼承IBURespository,撰寫風格與方式如下

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TestMVCAutoEntity.Models
{
    public class BURespository : TestMVCAutoEntity.Models.IBURespository
    {
        DWCEntities db = new DWCEntities();

        //
        // Query Methods

        public IQueryable FindAllBU()
        {
            return db.DWC_DT_BU;
        }
        public IQueryable FindByBG(int bg_key)
        {
            return db.DWC_DT_BU.Where(d => d.BG_KEY == bg_key);
        }
        public IQueryable FindByCode(string Cmr_BU_Code)
        {
            return db.DWC_DT_BU.Where(d => d.CMR_BU_CODE == Cmr_BU_Code);
        }
        public DWC_DT_BU GetBU(int bu_key)
        {
            return db.DWC_DT_BU.SingleOrDefault(d => d.BU_KEY == bu_key);
        }

        //
        // Insert/Delete Methods

        public void Add(DWC_DT_BU _DWC_DT_BU)
        {
            db.DWC_DT_BU.AddObject(_DWC_DT_BU);
        }

        public void Delete(DWC_DT_BU _DWC_DT_BU)
        {
            db.DWC_DT_BU.DeleteObject(_DWC_DT_BU);
        }
        //
        // Persistence 

        public void Save()
        {
            db.SaveChanges();
        }
    }
}

 

 

 

http://www.plurk.com/SophieQ