开发者

LINQ to SQL Could not find key member. Only fails on server

开发者 https://www.devze.com 2022-12-10 07:18 出处:网络
I have a scenario where I am inheriting from an abstract class in my partial linq to sql auto generated class implementation. My base abstract class has an abstract property called ID which I have fla

I have a scenario where I am inheriting from an abstract class in my partial linq to sql auto generated class implementation. My base abstract class has an abstract property called ID which I have flagged inside my LINQ to SQL model with the instance modifier override. This works fine locally without any issues. I have also done some development on another machine and it works fine there too (both in VS2008 and using Subversion). I am running CI with TeamCity and the build succeeds and deploys as desired. The problem is when the server tries to hit the database for the first time via the LINQ to SQL data context, it generates the follo开发者_Python百科wing error.

"Could not find key member 'Id' of key 'Id' on type 'CustomType'. The key may be wrong or the field or property on 'CustomType' has changed names."

I have tried changing my configuration by not implementing the Id field in my base class but this still fails. Why does it work on both of my DEV machines but not on the server? I am using LINQ to SQL in another project that runs on this server just fine.

FYI: LINQ to SQL, SQL 2008, .NET 3.5, SERVER 2008, IIS 7.0

UPDATE

I have gone back and added the same table a second time in the same data model but without a base class and have then displayed the results from that table and got no errors. This tells me it has something to do with my base abstract class and the need to flag a property on one of my linq to sql model classes (that belongs to a key relationship) with the instance modifier of override. No answer to this yet but am getting closer.

UPDATE

I have fixed my issue by simply changing my approach to my problem but I am still interested in why this doesn't work. I created a new WinSrv2008 VPC and patched it, deployed a pre-built version of my site to it and still got the same error. I now assume the issue is like what the person said here, a dependency issue with VS2008. My question is what or what? Will install VS2008 on the VPC to see if it works after that.


Check that you have the same version of the dotnet framework installed on all machines.

It may be that you have 3.5 and not 3.5SP1 on the build server.

EDIT

See that the framework versions are the same, the other possibilities are:

  • Is it using some functionality that is included in Visual Studio, which is not installed on the server?
  • Is it some rights issue, are the calls being made in the security context of the same user?


Delete the associations between the table causing the problem and other tables in the .dbml file

0

精彩评论

暂无评论...
验证码 换一张
取 消