开发者

Specified cast is not valid querying Sharepoint

开发者 https://www.devze.com 2023-01-24 00:30 出处:网络
Using SPMETAL I\'ve generated a C# file allowing me the use of LINQ to access Sharepoint objects. However, using a very simple query produces a strange error:

Using SPMETAL I've generated a C# file allowing me the use of LINQ to access Sharepoint objects.

However, using a very simple query produces a strange error:

Specified cast is not valid.

Stack trace:

at Set__zleceniaTrigger(Object , Object ) at Microsoft.SharePoint.Linq.StaticPropertyMap.SetToEntity(Object entity, Object value) at Microsoft.SharePoint.Linq.SPItemMappingInfo.MaterializeEntity[TEntity](DataContext dc, SPDataList list, SPListItem item, SPItemMappingInfo itemMappingInfo, JoinPath joinPath) at lambda_method(Execu开发者_JAVA技巧tionScope , SPListItem ) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source) at QuickModify.Program.Main(String[] args) in C:\XXXXXXXXX\QuickModify\Program.cs:line 42 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()

The query itself looks like this:

SPEntitiesDataContext ctx = new SPEntitiesDataContext("http://localhost:1080");  
var tasks = ctx.Zlecenia.ToList();

Granted, this is not the most optimal query, but one which uses .Where to filter only the needed records also returns the same error.

I found I can select specific columns using .Select(z => new ZlecenieItem(){ ColumnName = z.ColumnName, ... }), however I cannot use this to select lookup columns, as I get the following error then (even if I select only a single column this way):

The query uses unsupported elements, such as references to more than one list, or the projection of a complete entity by using EntityRef/EntitySet.

This is problematic because sometimes I need to get values from other lists, and it would be nice to use the lookup values.

Did I just find my first ever genuine bug in a MS product, or (what feels a lot more likely) am I doing something wrong?


While I'm still unsure why the above didn't work, I managed to solve the problem by adding a custom configuration file to SPmetal to generate the reference with.

This would suggest that the default SPmetal configuration might not always work.

0

精彩评论

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

关注公众号