如何使用外键链接3个表?

时间:2018-05-27 10:06:59

标签: c# linq foreign-keys sql-server-express

我制作了一张名为&#34的桌子;预订"其中包含客户ID和房屋ID。我也为房屋和顾客制作了桌子。我创建了一个包含预留数据的数据网格,但我也希望它包含客户姓氏和房屋代码。

我的表是(在SQL Server Express中):

2018-05-27 14:23:28.980  INFO 8264 --- [           main] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-05-27 14:23:28.990 ERROR 8264 --- [           main] o.s.boot.SpringApplication               : Application startup failed

java.lang.reflect.UndeclaredThrowableException: Failed to invoke event listener method
HandlerMethod details: 
Bean [com.community.core.service.search.SolrIndexCleanupServiceImpl$$EnhancerBySpringCGLIB$$fa6b7973]
Method [public void com.community.core.service.search.SolrIndexCleanupServiceImpl.rebuildIndexAtStartupIfNecessary() throws org.broadleafcommerce.common.exception.ServiceException,java.io.IOException]
Resolved arguments: 

    at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:273) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.10.RELEASE.jar:1.5.10.RELEASE]
    at com.community.admin.AdminApplication.main(AdminApplication.java:18) [classes/:na]
Caused by: org.broadleafcommerce.common.exception.ServiceException: Could not delete documents
    at org.broadleafcommerce.core.search.service.solr.index.SolrIndexServiceImpl.deleteAllNamespaceDocuments(SolrIndexServiceImpl.java:339) ~[broadleaf-framework-5.2.3-GA.jar:na]
    at org.broadleafcommerce.core.search.service.solr.index.SolrIndexServiceImpl.preBuildIndex(SolrIndexServiceImpl.java:183) ~[broadleaf-framework-5.2.3-GA.jar:na]
    at org.broadleafcommerce.core.search.service.solr.index.SolrIndexServiceImpl.rebuildIndex(SolrIndexServiceImpl.java:174) ~[broadleaf-framework-5.2.3-GA.jar:na]
    at com.community.core.service.search.SolrIndexCleanupServiceImpl.rebuildIndexAtStartupIfNecessary(SolrIndexCleanupServiceImpl.java:54) ~[classes/:na]
    at com.community.core.service.search.SolrIndexCleanupServiceImpl$$FastClassBySpringCGLIB$$b84b8451.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673) ~[spring-aop-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    at com.community.core.service.search.SolrIndexCleanupServiceImpl$$EnhancerBySpringCGLIB$$fa6b7973.rebuildIndexAtStartupIfNecessary(<generated>) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:256) ~[spring-context-4.3.14.RELEASE.jar:4.3.14.RELEASE]
    ... 17 common frames omitted
Caused by: org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/catalog_reindex: Expected mime type application/octet-stream but got text/html. <html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
<p>Problem accessing /solr/catalog_reindex/update. Reason:
<pre>    Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>

</body>
</html>

    at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:528) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:234) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:226) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:135) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:896) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:859) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.apache.solr.client.solrj.SolrClient.deleteByQuery(SolrClient.java:874) ~[solr-solrj-5.3.1.jar:5.3.1 1703449 - noble - 2015-09-17 01:48:17]
    at org.broadleafcommerce.core.search.service.solr.index.SolrIndexServiceImpl.deleteAllNamespaceDocuments(SolrIndexServiceImpl.java:331) ~[broadleaf-framework-5.2.3-GA.jar:na]
    ... 35 common frames omitted

2018-05-27 14:23:28.992  INFO 8264 --- [           main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@3ba9ad43: startup date [Sun May 27 14:22:58 IRDT 2018]; root of context hierarchy
2018-05-27 14:23:28.998  INFO 8264 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase 0
2018-05-27 14:23:28.999  INFO 8264 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Stopping beans in phase -2147483648
2018-05-27 14:23:29.100  INFO 8264 --- [           main] c.b.autoconfigure.HSQLDBServer           : Stopping HSQL server...
[Server@3e073950]: Initiating shutdown sequence...
[Server@3e073950]: Shutdown sequence completed in 112 ms.
[Server@3e073950]: 2018-05-27 14:23:29.213 SHUTDOWN : System.exit() was not called
2018-05-27 14:23:29.225  INFO 8264 --- [           main] o.s.jmx.export.MBeanExporter             : Unregistering JMX-exposed beans on shutdown
2018-05-27 14:23:29.225  INFO 8264 --- [           main] o.s.jmx.export.MBeanExporter             : Unregistering JMX-exposed beans
2018-05-27 14:23:29.268  INFO 8264 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'blPU'
2018-05-27 14:23:29.269  INFO 8264 --- [           main] o.b.c.c.e.AbstractHydratedCacheManager   : Disposing of all hydrated cache members
2018-05-27 14:23:29.274  INFO 8264 --- [           main] o.b.c.c.e.AbstractHydratedCacheManager   : Disposing of all hydrated cache members
2018-05-27 14:23:29.280  INFO 8264 --- [           main] o.b.c.c.e.AbstractHydratedCacheManager   : Disposing of all hydrated cache members
2018-05-27 14:23:29.284  INFO 8264 --- [           main] o.b.c.c.e.AbstractHydratedCacheManager   : Disposing of all hydrated cache members
2018-05-27 14:23:29.294  INFO 8264 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'blCMSStorage'
2018-05-27 14:23:29.294  INFO 8264 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'blSecurePU'
2018-05-27 14:23:29.295  INFO 8264 --- [           main] o.s.jmx.export.MBeanExporter             : Unregistering JMX-exposed beans on shutdown
2018-05-27 14:23:29.295  INFO 8264 --- [           main] o.s.jmx.export.MBeanExporter             : Unregistering JMX-exposed beans
2018-05-27 14:23:29.309  INFO 8264 --- [           main] b.c.e.c.e.MergeEhCacheManagerFactoryBean : Shutting down EhCache CacheManager

我已经创建了所有表格,但我不知道如何正确链接它们。我想获取数据并将其放入数据网格中。

2 个答案:

答案 0 :(得分:0)

要从预订,客户的姓氏和住宅代码中选择所有数据,您需要运行查询:

Select R.*, C.Surname, H.Code 
From [dbo].[reservations] R
inner join [dbo].[customers]  C on C.Id = R.CustomerId
inner join [dbo].[houses]  H on H.Id = R.HouseId

答案 1 :(得分:0)

试试这个:

select r.*,c.surname,h.code from reservation r,customers c,houses h where 
r.customer_id=c.customer_id and r.house_id=h.house_id