开发者

Problem with GetTable Method in Linq 2 SQL

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜