首页 \ 问答 \ 使用.Contains()和linq-to-sql(using .Contains() with linq-to-sql)

使用.Contains()和linq-to-sql(using .Contains() with linq-to-sql)

我有以下查询接收作为参数的整数列表:

public int GetMostRecent(List<int> TheIDs)
{
 ...using MyDC...

   var TheMostRecentID = (from d in MyDC.Data
                           where TheIDs.Contains(d.ID)
                           orderby d.DateTime
                           select d.ID).LastOrDefault(); 
}

这是将参数集合中的列表与数据库中的数据进行匹配的最佳方式,还是比在linq-to-sql中使用.Contains()方法更好的方法。

谢谢。


I have the following query that receives a list of ints as a parameter:

public int GetMostRecent(List<int> TheIDs)
{
 ...using MyDC...

   var TheMostRecentID = (from d in MyDC.Data
                           where TheIDs.Contains(d.ID)
                           orderby d.DateTime
                           select d.ID).LastOrDefault(); 
}

Is this the best way to match a list within a parameter collection to data in the database or is there a better way than using the .Contains() method in linq-to-sql.

Thanks.


原文:https://stackoverflow.com/questions/9034673
更新时间:2022-05-03 09:05

最满意答案

1:

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  add_definitions(/DYOURDEFINITION)
endif()

2:如果我理解你的话,你需要创建一个选项变量

option(USE_OPENGL "Use OpenGL or DirectX")

然后在添加新目标时检查它:

if(USE_OPENGL)
add_subdirectory(OpenGL)
else()
add_subdirectory(DirectX)
endif()

当然,你应该在OpenGL /和DirectX / dirs中创建CMakeLists.txt。


1:

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  add_definitions(/DYOURDEFINITION)
endif()

2: If i understood you right, you need to create an option variable

option(USE_OPENGL "Use OpenGL or DirectX")

And then check for it when you are adding new target:

if(USE_OPENGL)
add_subdirectory(OpenGL)
else()
add_subdirectory(DirectX)
endif()

Of course, you should create CMakeLists.txt in OpenGL/ and DirectX/ dirs.

相关问答

更多
  • 第一个告诉你你现在正在使用哪一个(如果你说构建将构建哪个配置 - 如果你调试将启动哪个配置等) 第二个处理服务器将如何构建您的aspx / razor /等。 页面。 第三个就是这样,你可以在第一时间改变不同配置的设置! 最后一个告诉您要部署哪个配置 - 无论当前所选配置(从1开始)将显示什么 - 当然它将取决于3中的设置,并且很可能从2部署文件。 所以不 - 只有其中一个是不够的 The first one tells you in which one you are working right now ...
  • 尝试在文件夹C:/ Tmp中生成构建系统,以测试问题是否与损坏的缓存或路径问题有关。 要将其构建到问题中所述的文件夹: 检查您是否在“PM&R”个人文件夹中具有写入权限 更改生成器时删除cmake缓存 Try to generate build system in the folder C:/Tmp to test if the problem is related to corrupted cache or path issues. To build it to the folder stated in ...
  • 这不是Visual Studio特定的问题。 通常,C ++不保证使用一个版本的编译器构建的库将使用由同一编译器的不同版本或不同编译器构建的可执行文件。 这是因为C ++为编译器提供了如何生成其对象的二进制布局的一些自由。 这是一个非常古老的问题,没有简单的解决方案。 如果您不想接受对库接口的任何限制,则需要为每个受支持的编译器版本重建库,并进行严格的ABI更改(这通常意味着编译器版本中每个编译器和主要版本的单独构建) )。 CMake无法为您执行此操作,因为每个CMake配置运行仅为一个特定编译器生成CM ...
  • 是的,但不是很漂亮...... 您需要更新所有目标上的RUNTIME_OUTPUT_DIRECTORY , LIBRARY_OUTPUT_DIRECTORY和ARCHIVE_OUTPUT_DIRECTORY属性。 您需要为每个配置执行此操作(Debug,RelWithDebInfo等) 最简单的方法是使用CMAKE _...等效项“全局”执行此操作。 例如,检查以下示例,它将bin /和lib /设置为“全局”二进制文件/库输出目录: # First for the generic no-config ca ...
  • 如果您在解决方案资源管理器中右键单击该解决方案并访问属性,您将看到一个属性对话框,让您选择配置属性。 在该对话框的右上角,您将看到一个配置管理器按钮。 点击它启动配置管理器对话框。 单击活动解决方案配置下拉列表,然后选择新建...以进行新配置。 见下面的截图。 If you right-click the solution in Solution Explorer and access properties you will see a properties dialog that lets you sel ...
  • 1: if(CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions(/DYOURDEFINITION) endif() 2:如果我理解你的话,你需要创建一个选项变量 option(USE_OPENGL "Use OpenGL or DirectX") 然后在添加新目标时检查它: if(USE_OPENGL) add_subdirectory(OpenGL) else() add_subdirectory(DirectX) endif() 当然,你应该在 ...
  • 尝试更新您的CMake版本。 CMake 3.1的cmake-gui的Configue对话框将相应的条目列为Visual Studio 12 2013 : 在较早的CMake版本(3.0以前)中,这些条目省略了年份,仅显示版本号,因此条目只是读取Visual Studio 12 。 如果您的CMake版本更旧,则可能根本不支持Visual Studio 2013。 但是,您仍然应该能够打开为旧版Visual Studio版本生成的项目文件。 这可能需要Visual Studio进行额外的转换步骤,这可能会使 ...
  • 经过一番挖掘,我可以自己回答,我会为其他可能会遇到这个问题的人发布答案。 方法2是正确答案,但由于列表变量LIBS_DEBUG和LIBS_RELEASE ,它无法正常工作 。 看来列表扩展在generator-expression中没有完全正常工作,我发现了一个可能与之相关的旧bug 。 解决方案是自己扩展列表,然后在列表的每个元素上调用generator-expression。 这个解决方案对我有用: foreach(DL ${LIBS_DEBUG}) target_link_libraries(MyPr ...
  • 这会将问题的第一部分的复选框设置为未选中状态: set_property(TARGET PROPERTY EXCLUDE_FROM_DEFAULT_BUILD_DEBUG TRUE) 现在我想知道,编译器命令行来自哪里,因为/D_DEBUG在所有具有属性的对话框中都没有,Visual Studio已经向我展示了(问题的第二部分)。 我正在VS2013中构建这个项目。 最初,该字符串/D_DEBUG存在于项目属性 - > C / C ++ - ...
  • 您可以使用LINK_FLAGS目标属性添加自定义链接器选项: add_executable(foo ${FOO_SOURCES}) if(MSVC) set_property(TARGET foo APPEND PROPERTY LINK_FLAGS /DEBUG) endif() 这将为Visual Studio构建中的所有配置设置/DEBUG标志。 也可以仅为特定配置添加标志。 请注意,这实际上只设置了链接器标志而没有其他内容。 如果您想要一个功能齐全的调试版本,您还必须设置其他标志。 正如评 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)