共享主机上的Linq 2 SQL
时间:2020-03-05 18:42:40 来源:igfitidea点击:
我最近在共享主机上遇到了linq的问题。
主机是Shared Intellect,它们支持框架的v3.5. 但是,我不确定他们是否安装了SP1. 我怀疑他们没有。
我有一个简单的" News"表,其结构如下:
NewsID uniqueidentifier Title nvarchar(250) Introduction nvarchar(1000) Article ntext DateEntered datetime (default getdate()) IsPublic bit (default true)
我的目标是显示该表中的3条最新记录。最初,我采用了D&D方法(我知道,我知道),并创建了一个linq数据源,无法找到以所需方式限制结果的方法,因此我删除了该方法并编写了以下内容:
var dc = new NewsDataContext(); var news = from a in dc.News where a.IsPublic == true orderby a.DateEntered descending select new { a.NewsID, a.Introduction }; lstNews.DataSource = news.Take(3); lstNews.DataBind();
这在我的本地计算机上完美运行。
但是,当我将所有内容上传到共享主机时,出现以下错误:
.Read_<>f__AnonymousType0`2 (System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1<System.Data.SqlClient.SqlDataReader>) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.MethodAccessException: .Read_<>f__AnonymousType0`2 (System.Data.Linq.SqlClient.Implementation.ObjectMaterializer`1<System.Data.SqlClient.SqlDataReader>)
我尝试在Google上搜索错误,但未成功。然后,我尝试以我能想到的各种方式修改查询,删除where / orderby参数的各种组合,以及将查询限制为单个列,甚至删除Take命令。
因此,我的问题分为三个部分:
- 是否还有其他人遇到过这种情况?如果是,是否有"快速"解决方案?
- 有没有一种方法可以使用数据源来限制行?
- 有没有什么方法可以确定共享主机缺少哪个版本的框架,而没有直接通过电子邮件发送它们(我已经完成并正在等待答案)
解决方案
回答
当框架缺少程序集或者其中一个引用的版本错误时,框架将抛出" System.MethodAccessException"。
我要做的第一件事是尝试将代码上载并引用到BIN中的LINQ程序集,而不是共享托管提供程序GAC。