开发者

Problem with GetTable Method in Linq 2 SQL

开发者 https://www.devze.com 2023-01-30 11:49 出处:网络
Hi All I write this code: using (NWindDataContext context = new NWindDataContext()) { var table = context.GetTable<T>();

Hi All I write this code:

using (NWindDataContext context = new NWindDataContext())
{
  var table = context.GetTable<T>();
  return table.ToList();
}

and assign return value to a datagridview.the problem is when table has foreign key result value has reference to related table开发者_开发问答s and binding going to Exception. How to get just columns of a table with generic method that accept T type and return columns of Corresponding Table. thanks Alot


public static List<T> SelectAll<T>() where T : class
        {
            try
            {
                using (NWindDataContext context = new NWindDataContext())
                {
                    var table = context.GetTable<T>();
                    return table.ToList();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

and Use Of it:

public void UpdateDataGrid()
        {
            dataGridView1.DataSource = Repository.SelectAll<Order>();
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消