这适用于具有 View 表的现有数据库。试图列出一个视图表,但在我的操作中遇到了这个错误消息:
CREATE DATABASE permission denied in database 'master'.
要访问的视图表称为:SomeTable
如果你在数据库(ServerA_dev_alpha_custom)上运行它:
sp_helptext 'SomeTable'
你会得到这个:
CREATE VIEW dbo.[SomeTable] AS SELECT * FROM ServerA_dev_alpha.dbo.[SomeTable]
这是模型:
public class SomeTable
{
[Key]
public virtual string SomeTableid { set; get; }
public virtual string name { set; get; }
public virtual string formvalue { set; get; }
public virtual string status { set; get; }
public virtual DateTime CreateDate { set; get; }
}
班级名称:
public class SomeDB: DbContext
与连接字符串名称完全匹配:
<add name ="SomeDB"
connectionString ="data source=ServerA\DBSome; integrated Security=SSPI; initial catalog=ServerA_dev_alpha_custom"
providerName="System.Data.SqlClient"/>
在创建模型时发现错误:
SomeDB _db = new SomeDB();
var model = (from c in _db.SomeTable
orderby c.CreateDate descending
select c).Take(20);
当我将连接字符串更改为指向表的定义位置时: ServerA_dev_alpha (database) 它可以工作。
有任何想法吗?