EF中获取当前上下文的表名

EF在处理并发上并不是很好,很多时候我们需要手动写sql操作数据库。但是在基类中我们如何获取当前服务上下问操作的表呢?

使用正则是其中一种解决办法

var sql= Repository.Table.ToString();
var regex = new Regex("FROM (?.*) AS");
var match = regex.Match(sql);
string table = match.Groups["table"].Value;

其中sql=

SELECT "Extent1"."uuid", "Extent1"."imageid", "Extent1"."description", "Extent1"."order", "Extent1"."tags", "Extent1"."isdefault", "Extent1"."billid", "Extent1"."filename",
"Extent1"."fileext", "Extent1"."filesize", "Extent1"."storepath", "Extent1"."storename", "Extent1"."createby", "Extent1"."createon", "Extent1"."updateby", "Extent1"."updateon"
FROM "dbo"."plm_commissionerinfoimage" AS "Extent1"

你可能感兴趣的:(EF中获取当前上下文的表名)