使用LINQ to SQL确定主键 [英] Determine primary key using LINQ to SQL

查看:70
本文介绍了使用LINQ to SQL确定主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个基于LINQ to SQL的存储库,我想在其中允许带有int参数的GetByID.签名是:

I'm writing a LINQ to SQL based repository where I want to allow a GetByID with an int parameter. The signature is:

public T GetByID(int id)
{
     // Return
     return _dataContext.GetTable<T>() ....;
}

我的表的主键名称不同.我想做的是为每个T动态确定主键是什么,并向其查询整数= id的值.有什么想法可以最好地实现这一目标吗?

My tables have different names for the primary key. What I'd like to do is determine dynamically for each T what the primary key is and query it for a value of integer = id. Any ideas how to best pull this off?

推荐答案

Dennis Troller answered it to the question that Ben linked to in the comments in the question.

这篇关于使用LINQ to SQL确定主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆