我正在尝试使用EF4创建一个通用方法来查找对象的主键.
例
public string GetPrimaryKey<T>()
{
...
}
Run Code Online (Sandbox Code Playgroud)
为了提供更多信息,我正在使用Tekpub StarterKit,下面是我试图启动和运行的类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Objects;
using System.Data.Objects.ELinq;
using System.Data.Linq;
using Web.Infrastructure.Storage.EF4;
namespace Web.Infrastructure.Storage {
public class EFSession:ISession {
PuzzleEntities _db;//This is an ObjectContext
public EFSession() {
_db = new PuzzleEntities();
}
public void CommitChanges() {
_db.SaveChanges();
}
/// <summary>
/// Gets the table provided by the type T and returns for querying
/// </summary>
private ObjectSet<T> GetObjectSet<T>() where T:class {
return _db.CreateObjectSet<T>();
}
private T …
Run Code Online (Sandbox Code Playgroud)