この関数は EntityFramework 4.0 (ObjectContext) で使用しています。現在、EF 5.0 を使用しています。私の問題はDefaultContainerName
、GetObjectByKey
メソッドが見つからないことですDBContext
public static T GetObjectByID<T>(int ID, string tableName = "")
{
var localDB = new LocalBaseEntities();
string entitySetName = string.Format("{0}.{1}", localDB.DefaultContainerName, string.IsNullOrEmpty(tableName) ? typeof(T).Name + "s" : tableName);
try
{
IEnumerable<KeyValuePair<string, object>> entityKeyValues =
new KeyValuePair<string, object>[] { new KeyValuePair<string, object>(typeof(T).Name + "ID", ID) };
EntityKey key = new System.Data.EntityKey(entitySetName, entityKeyValues);
return (T)localDB.GetObjectByKey(key);
}
catch (Exception)
{ }
return default(T);
}
この関数を変換するには?
または、このような機能を作成する方法は?