FirstOrDefault“锁定在内部" *

编程入门 行业动态 更新时间:2024-10-22 17:21:06
本文介绍了FirstOrDefault“锁定在内部" * _InitializeDataWorkspace的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个奇怪的场景,我无法运行".FirstOrDefault"屏幕中的* _InitializeDataWorkspace方法.

I have a strange scenario whereI can't run a ".FirstOrDefault" inside a screen *_InitializeDataWorkspace method.

当我添加断点时,实体列表/表似乎被锁定/处于待命状态,直到打开了另一个可以从数据库中成功检索项目的屏幕.

When I add breakpoints it seems likethe entity list/tableis locked/placed on hold, untill another screen was opened that would successfully retrieve items from the database.

有什么想法吗?将不胜感激.

Any ideas? Would be much appreciated.

partial void CreateNewPerson_InitializeDataWorkspace(List<IDataService> saveChangesTo) { //Code gets "locked" here: City city = this.DataWorkspace.ApplicationData.Cities.FirstOrDefault(); //And proceed to this only when I open a different screen that load data from the database sucessfully if (city != null) { PersonProperty.City = city; } }

推荐答案

我从来没有遇到过这种情况,&我在 InitializeDataWorkspace中初始化属性 始终保持这种方法.

I've never had this happen to me, & I initialise properties in the InitializeDataWorkspace method all the time.

不过有几点评论:

  • 您意识到, FirstOrDefault 这样使用,没有 lambda表达式,它将返回表中的第一条记录;如果不存在,则返回null,对吗?可能是碰巧首先添加到表中的任何记录.
  • 如果我知道要初始化的记录的ID,我倾向于使用 SingleOrDefault . (使用简单的lambda表达式" x => x.ID = myKnownIdValue ").
  • 这几天,我实际上添加了 query参数到屏幕上以表示我想参考的任何实体集合,用那个代替 DataWorkspace.DataSourceName .通过将查询添加到屏幕,LightSwitch现在知道"消息.关于它的& ;,将其包括在幕后的任何东西"中.它做到了.当然,它可能根本没有优势,但这就是我开始做的事情. 因此,您之前的代码将具有" this.queryParamaterName.FirstOrDefault(x => x.ID == aKnownIdValue)".
  • You realise that FirstOrDefault, used like that, with no lambda expression, is going to return the first record in the table, or null if none exist, right? It could be any record that happened to be added to the table first.
  • I tend to useSingleOrDefault, if I know theID of the record I want to initialise with (with a simple lambda expression "x => x.ID = myKnownIdValue").
  • These days I add actually a query parameter to the screen to represent any entity collection I want to reference, & use that instead of using DataWorkspace.DataSourceName. By adding the query to the screen, LightSwitch now "knows" about it &, includes it in whatever behind the scenes "stuff" that it does. Of course it may provide no advantage at all, but it's what I've started doing. So your code earlier would have "this.queryParamaterName.FirstOrDefault(x => x.ID == aKnownIdValue)".

我希望对您有帮助?

更多推荐

FirstOrDefault“锁定在内部" *

本文发布于:2023-06-04 19:10:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/503382.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:在内部   FirstOrDefault   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!