组合框使用相同的.edmx源

时间:2014-05-07 17:38:24

标签: c# linq visual-studio combobox edmx

我使用.edmx数据源相对较新,但我在将多个组合框加载到同一数据源时遇到问题。这是我的代码。

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;

 namespace RatingDepartmentRates
 {
public partial class Form1 : Form
{
    private VSCSystemEntities _VSCSystem = new VSCSystemEntities();
   // public VSCSystemEntities VSCSystemEntity { get { return _VSCSystem; } }

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        cmbDealers.Items.Clear();
        cmbCarriers.Items.Clear();
        loadDealers();
        loadCarriers();

    }

    public void loadDealers()
    {
        var allDealers = from Z in _VSCSystem.tblRptDealerAddresses
                         select Z.chvVSCName;
        foreach (var item in allDealers)
        {
            cmbDealers.Items.Add(item);
        }

    }

    public void loadCarriers()
    {
        var allCarriers = _VSCSystem.tblCarrierMasters
      // .Where(x => x.EMAIL == givenInfo || x.USER_NAME == givenInfo)
       .Select(Z => new { Z.intCarrierCode, Z.chvCarrierName });
        foreach (var item in allCarriers)
        {
            cmbCarriers.Items.Add(item.intCarrierCode + " - " + item.chvCarrierName);
        }

    }


}
 }

如果我注释掉一个加载功能,另一个加载功能,反之亦然

0 个答案:

没有答案