相关疑难解决方法(0)

实体框架4:如何找到主键?

我正在尝试使用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)

.net c# entity-framework primary-key entity-framework-4

13
推荐指数
3
解决办法
3万
查看次数