Entity Framework: Get mapped table name from an entity
The extension methods I have created one extension method for DbContext and other for ObjectContext: public static class ContextExtensions
{
public static string GetTableName<T>(this DbContext context) where T : class
{
ObjectContext objectContext = ((IObjectContextAdapter) context).ObjectContext; return objectContext.GetTableName<T>();
} public static string GetTableName<T>(this ObjectContext context) where T : class
{
string sql = context.CreateObjectSet<T>().ToTraceString();
Regex regex = new Regex("FROM (?<table>.*) AS");
Match match = regex.Match(sql); string table = match.Groups["table"].Value;
return table;
}
} Using the code Getting the mapped table name for an entity named Album, using a ObjectContext object: ObjectContext context = ....;
string table = context.GetTableName<Album>(); Or using a DbContext object: DbContext context = ....;
string table = context.GetTableName<Album>();
原文 Entity Framework: Get mapped table name from an entity
Entity Framework: Get mapped table name from an entity的更多相关文章
- Entity FrameWork(实体框架)是以ADO.NET Entity FrameWork ,简称为EF
Entity FrameWork(实体框架)是以ADO.NET Entity FrameWork ,简称为EF Entity FrameWork的特点 1.支持多种数据库(MSSQL.Oracle.M ...
- Entity Framework Tutorial Basics(3):Entity Framework Architecture
Entity Framework Architecture The following figure shows the overall architecture of the Entity Fram ...
- Entity Framework Code-First(10.2):Entity Mappings
Entity Mappings using Fluent API: Here, we will learn how to configure an entity using Fluent API. W ...
- entity framework 新手入门篇(3)-entity framework实现orderby,count,groupby,like,in,分页等
前面我们已经学习了entityframework的基本的增删改查,今天,我们将在EF中实现一些更加贴近于实际功能的SQL方法. 承接上面的部分,我们有一个叫做House的数据库,其中包含house表和 ...
- entity framework 新手入门篇(2)-entity framework基本的增删改查
经过前两节的简单描述,终于可以进入entity framework的使用部分了.本节将对entity framework原生的增删改查进行讲解. 承接上面的部分,我们有一个叫做House的数据库,其中 ...
- Entity Framework学习笔记(六)----使用Lambda查询Entity Framework(1)
请注明转载地址:http://www.cnblogs.com/arhat 在前几章中,老魏一直使用Linq来查询Entity Framework.但是老魏感觉,如果使用Linq的话,那么Linq的返回 ...
- entity framework 新手入门篇(4)-entity framework扩展之 entityframework.extended
对于EF的操作,我们已经有了大概的了解了,但对于实战来说,似乎还欠缺着一些常用的功能,那就是批量的删除,更新数据. 承接上面的部分,我们有一个叫做House的数据库,其中包含house表和seller ...
- Entity Framework Tutorial Basics(10):Entity Lifecycle
Entity Lifecycle: Before we work on CRUD operation (Create, Read, Update, Delete), it's important to ...
- Entity Framework Many to Many Relation Mapping(Entity Framework多对多关系映射)
通常我们在做数据库设计时都会有两张表是多对多关系的时候,在数据库做多对多关系时候我们通常通过中间关联表来处理,那我们现在在EF中是如何处理的呢? 假设我们有如下关系,用户(User)包含多个角色(Ro ...
随机推荐
- 使用微软分布式缓存服务Velocity(Windows Server AppFabric Caching Service)
概述 Velocity是微软推出的分布式缓存解决方案,为开发可扩展性,可用的,高性能的应用程提供支持,可以缓存各种类型的数据,如CLR对象. XML.二进制数据等,并且支持集群模式的缓存服务器.Vel ...
- Oracle bbed 实用示例-----File Header Reset
一.查看当前环境 1.1 当前控制文件中的SCN号 [oracle@ora10 ~]$ sqlplus /nolog SQL :: Copyright (c) , , Oracle. All righ ...
- matlab实现的嵌套乘法、高精度、二分法
嵌套乘法的计算: \[ P(x) = 1 - x + x^2 - x^3 + ...+ x ^ {98} - x^{99} \] function y = nest( d, c, x, b ) if ...
- 时序图 Sequence Diagram
时序图(Sequence Diagram)是显示对象之间交互的图,这些对象是按时间顺序排列的. 时序图中显示的是参与交互的对象及其对象之间消息交互的顺序. 下面这张图介绍了时序图的基本内容: 下面这张 ...
- Halcon学习笔记之缺陷检测(二)
例程:detect_indent_fft.hdev 说明:这个程序展示了如何利用快速傅里叶变换(FFT)对塑料制品的表面进行目标(缺陷)的检测,大致分为三步: 首先,我们用高斯滤波器构造一个合适的滤波 ...
- Android 自定义Toast,不使用系统Toast
效果图: 创建Toast类 package com.example.messageboxtest; import android.app.Activity; import android.conten ...
- Python求算数平方根和约数
一.求算术平方根 a=0 x=int(raw_input('Enter a number:')) if x >= 0: while a*a < x: a = a + 1 if a*a != ...
- c++ 继承多个类 及虚函数
#include <iostream>using namespace std; class BaseA {public: virtual void say() { co ...
- [设计模式] 12 代理模式 proxy
在GOF的<设计模式:可复用面向对象软件的基础>一书中对代理模式是这样说的:为其他对象提供一种代理以控制对这个对象的访问.结合上面的游戏代理的例子和下面的图,我们来进行分析一下.以前你是这 ...
- JavaScript 函数参数是传值(byVal)还是传址(byRef)?
对于“JavaScript 函数参数是传值(byVal)还是传址(byRef)”这个问题,普遍存在一个误区:number,string等“简单类型”是传值,Number, String, Object ...