实体框架加入(Entity Framework Join)
我尝试加入实体框架,但我需要在加入我的常规方法后列出我的信息,如下所示:
public DataTable LoadAllAllowing() { var resultList = new DataTable(); SqlConnection connection = new SqlConnection(@"server=. ; database=PersonnelTrackingSystem;Trusted_Connection=yes"); connection.Open(); SqlDataAdapter da = new SqlDataAdapter(@"SELECT PA.personelId ,[allowedDatesId] ,[allowedStartDate] ,[allowedEndDate] ,[allowReason] ,PI.personnelNumber ,PI.personnelName ,PI.personnelSurname FROM [PersonnelTrackingSystem].[dbo].[personnelAllowedDates] AS PA JOIN PersonnelInformation AS PI ON PI.personelId=PA.personelId", connection); da.Fill(resultList); return resultList; }
我如何用实体框架做到这一点? 我确实喜欢这个,但它不起作用
public List<PersonnelInfoAndAllow> LoadAllAllowing() { PersonnelTrackingSystemEntities entity = new PersonnelTrackingSystemEntities(); //var personnel = entity.personnelAllowedDates.ToList(); var allows = (from allow in entity.personnelAllowedDates join personnel in entity.PersonnelInformation on allow.personelId equals personnel.personelId select new { personelId = personnel.personelId, personnelNumber = personnel.personnelNumber, personnelName = personnel.personnelName, personnelSurname = personnel.personnelSurname, allowedDatesId = allow.allowedDatesId, allowedStartDate = allow.allowedStartDate, allowedEndDate = allow.allowedEndDate, allowReason = allow.allowReason }).ToList(); List<PersonnelInfoAndAllow> personnels = allows; return personnels;}
我写这样的课:
namespace personnelTrackingSystem { class PersonnelInfoAndAllow { public int personelId { get; set; } public System.DateTime allowedStartDate { get; set; } public System.DateTime allowedEndDate { get; set; } public string allowReason { get; set; } public int allowedDatesId { get; set; } public string personnelNumber { get; set; } public string personnelName { get; set; } public string personnelSurname { get; set; } } }
但它不起作用。 我怎么解决这个问题?I try to do join with entity framework but I need to List my information after join my normal method like this:
public DataTable LoadAllAllowing() { var resultList = new DataTable(); SqlConnection connection = new SqlConnection(@"server=. ; database=PersonnelTrackingSystem;Trusted_Connection=yes"); connection.Open(); SqlDataAdapter da = new SqlDataAdapter(@"SELECT PA.personelId ,[allowedDatesId] ,[allowedStartDate] ,[allowedEndDate] ,[allowReason] ,PI.personnelNumber ,PI.personnelName ,PI.personnelSurname FROM [PersonnelTrackingSystem].[dbo].[personnelAllowedDates] AS PA JOIN PersonnelInformation AS PI ON PI.personelId=PA.personelId", connection); da.Fill(resultList); return resultList; }
How I can do this with entity framework? I did like this but it doesn't work
public List<PersonnelInfoAndAllow> LoadAllAllowing() { PersonnelTrackingSystemEntities entity = new PersonnelTrackingSystemEntities(); //var personnel = entity.personnelAllowedDates.ToList(); var allows = (from allow in entity.personnelAllowedDates join personnel in entity.PersonnelInformation on allow.personelId equals personnel.personelId select new { personelId = personnel.personelId, personnelNumber = personnel.personnelNumber, personnelName = personnel.personnelName, personnelSurname = personnel.personnelSurname, allowedDatesId = allow.allowedDatesId, allowedStartDate = allow.allowedStartDate, allowedEndDate = allow.allowedEndDate, allowReason = allow.allowReason }).ToList(); List<PersonnelInfoAndAllow> personnels = allows; return personnels;}
I write class like that :
namespace personnelTrackingSystem { class PersonnelInfoAndAllow { public int personelId { get; set; } public System.DateTime allowedStartDate { get; set; } public System.DateTime allowedEndDate { get; set; } public string allowReason { get; set; } public int allowedDatesId { get; set; } public string personnelNumber { get; set; } public string personnelName { get; set; } public string personnelSurname { get; set; } } }
But it doesn't work. How I fix this ?
原文:https://stackoverflow.com/questions/32907194
最满意答案
You can go through below links to know more :
相关问答
更多-
基本上Spring是一个依赖注入的框架,它是一种允许构建非常分离的系统的模式。 问题 例如,假设您需要列出系统的用户,然后声明一个名为UserLister的接口: public interface UserLister { List
getUsers(); } 也许实现访问数据库以获取所有用户: public class UserListerDB implements UserLister { public List getUsers() { // ... -
有不同设计模式的负载,但有一些明显的设计模式: 代理 - 在AOP中大量使用和远程处理 。 在Spring配置文件中定义的Singleton - bean默认是单例。 模板方法 - 广泛用于处理样板重复代码(如关闭连接等)。 例如JdbcTemplate , JmsTemplate , JpaTemplate 。 更新以下注释:对于MVC,您可能需要阅读MVC参考 MVC中使用的一些明显的模式: 模型视图控制器 :-)。 Spring MVC的优点是您的控制器是POJO,而不是servlet。 这使得控制器 ...
-
我已经在https://stackoverflow.com/questions/1549472/what-are-upcoming-trends-in-software-industry-and-its-impact-for-java-developer/1549740#1549740中给出了部分答案,但我在这个答案中添加一些链接。 其实我不会介绍或讨论Spring的技术质量,因为它们不是新的,不能在我看来解释嗡嗡声。 相反,请考虑以下事件和收购: 2008年11月11日: SpringSource收购G2 ...
-
条纹框架[已关闭](Stripes Framework [closed])[2023-04-06]
官方的快速入门指南提供了一步一步的指南,让您可以使用Stripes进行启动和运行(该指南涵盖了基本配置以及第一个Stripes应用程序的开发)。 如果您不理解说明,那么我建议遵循@ seanizer的建议,并首先从Web层上的Java EE教程开始。 在进一步学习之前,你确实需要掌握基本技能。 不要把马车放在马前。 The official Quick Start Guide provides a step by step guide to get you up and running with Strip ... -
Spring框架[关闭](Spring framework [closed])[2023-10-06]
对于初学者这些网站是优选的: 教程点 玫瑰印度 java2s dzone 你可以在youtube上获得hundrades的视频。 教程点是新手的最佳选择。 春天我们有很多电子书,只是去谷歌搜索。 选一本你的标准可以理解的书。 祝一切顺利.. for beginners these sites are preferable: tutorials point rose india java2s dzone you can get hundrades of videos in youtube. tutorials ... -
该代码未使用| 在if语句中。 它在if语句的主体中使用它是非常不同的。 在那里使用时,它是按位或操作。 编辑: @RohitJain在他的评论中提供了比我更好的链接: http : //en.wikipedia.org/wiki/Bitwise_operation#OR 如果它在if语句中使用,如下所示: if (foo() | bar()) 这意味着“不要短路”。 如果foo()返回“true”,它仍将评估bar() 。 如果你用过|| 并且foo()返回“true”,它不会计算bar()因为它知道i ...
-
看看这个javascript逻辑运算符列表: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Logical_Operators 和比较运算符: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/Comparison_Operators Check out this list of javascript logical ...
-
你可以简单地使用NSView的setBoundsRotation:方法来设置它而不需要CoreAnimation。 如果你真的想使用CoreAnimation,你会这样: // make NSView myView a layer-backed view [myView setWantsLayer:YES]; // now get that CALayer and set the affineTransform of it, specifying the angle [myView.layer setAff ...
-
您可以通过以下链接了解更多信息: 春季论坛 弹簧3-0-VS-Java的EE-6-0 Spring vs Java EE 为什么Java EE失去了和春天赢了 You can go through below links to know more : spring forum spring-3-0-vs-java-ee-6-0 Spring vs Java EE Why Java EE Lost and Spring Won
-
如果您想使用Spring Integration的TCP和UDP支持 ,请求您只是接收UDP消息并对该消息执行某些操作,您应该按照以下步骤操作: 创建消息使用者 package com.example.udp; import org.springframework.messaging.Message; public class UDPConsumer { @Autowire what you want, this will be a Spring Bean @ServiceActiv ...