ASP.NET MVC 表外键问题

qq_30548569 2018-08-13 02:15:27
A表
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace ZY.Domain.Customer
{
public class tm_officialMatchGroup
{
[Key]
[ForeignKey("tm_officialMatchGroupInfo")]
public string groupid { get; set; }

public string groupname { get; set; }

public DateTime createdate { get; set; }

public int matchid { get; set; }

public bool iseffective { get; set; } = false;

public virtual List<tm_officialMatchGroupInfo> tm_officialMatchGroupInfo { get; set; }

[ForeignKey("tm_officialMatchcode")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }
}
}


B表
using System.ComponentModel.DataAnnotations.Schema;

namespace ZY.Domain.Customer
{
public class tm_officialMatchcode
{

// [ForeignKey("tm_officialTeam")]
public string groupid { get; set; }
// public string groupname { get; set; }
public int id { get; set; }
public int type { get; set; }
public int matchid { get; set; }
public string teamid1 { get; set; }
public string teamid2 { get; set; }
public string winer { get; set; }
public int teamidfen1 { get; set; }
public int teamidfen2 { get; set; }
// public virtual tm_officialTeam tm_officialTeam { get; set; }
}
}




c表
using System.ComponentModel.DataAnnotations.Schema;

namespace ZY.Domain.Customer
{
public class tm_officialMatchGroupInfo
{
public int id { get; set; }

[ForeignKey("tm_officialTeam")]
public string teamid { get; set; }

public string groupid { get; set; }

public int matchid { get; set; }

public string groupinfoName { get; set; }

public int groupsequence { get; set; }

public virtual tm_officialTeam tm_officialTeam { get; set; }
}
}


使用MODEL 时候 @model List<ZY.Domain.Customer.tm_officialMatchGroup>
读取c表正常 没有问题 而读取B表提示
很诧异 求高手解答
...全文
364 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
正怒月神 版主 2018-08-13
  • 打赏
  • 举报
回复
引用 8 楼 qq_30548569 的回复:
这个表 tm_officialTeam 应该不影响 吧?

你直接用ef生成一下,然后照搬一下就好了。
肯定是主外键设置的有问题。具体原因,也肯定出在b表的关联设置上。
qq_30548569 2018-08-13
  • 打赏
  • 举报
回复
这个表 tm_officialTeam 应该不影响 吧?
qq_30548569 2018-08-13
  • 打赏
  • 举报
回复
引用 6 楼 hanjun0612 的回复:
[quote=引用 3 楼 qq_30548569 的回复:]
[quote=引用 2 楼 hanjun0612 的回复:]
[ForeignKey("tm_officialMatchGroupInfo")]
public string groupid { get; set; }

public string groupname { get; set; }

public DateTime createdate { get; set; }

public int matchid { get; set; }

public bool iseffective { get; set; } = false;

public virtual List<tm_officialMatchGroupInfo> tm_officialMatchGroupInfo { get; set; }

[ForeignKey("matchid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }

我是以groupid 做关联的
[ForeignKey("groudid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }
这么做后缺报错
调用c表 缺没有问题 为什么呢[/quote]
B表
// public virtual tm_officialTeam tm_officialTeam { get; set; }
为什么注释了?[/quote] 前端并没有调用 这个表的内容 就注释了 这是另外一个表了
正怒月神 版主 2018-08-13
  • 打赏
  • 举报
回复
引用 3 楼 qq_30548569 的回复:
[quote=引用 2 楼 hanjun0612 的回复:]
[ForeignKey("tm_officialMatchGroupInfo")]
public string groupid { get; set; }

public string groupname { get; set; }

public DateTime createdate { get; set; }

public int matchid { get; set; }

public bool iseffective { get; set; } = false;

public virtual List<tm_officialMatchGroupInfo> tm_officialMatchGroupInfo { get; set; }

[ForeignKey("matchid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }

我是以groupid 做关联的
[ForeignKey("groudid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }
这么做后缺报错
调用c表 缺没有问题 为什么呢[/quote]
B表
// public virtual tm_officialTeam tm_officialTeam { get; set; }
为什么注释了?
qq_30548569 2018-08-13
  • 打赏
  • 举报
回复
顶一下顶一下顶一下顶一下
qq_30548569 2018-08-13
  • 打赏
  • 举报
回复
B C 我没感觉出有什么区别
qq_30548569 2018-08-13
  • 打赏
  • 举报
回复
引用 2 楼 hanjun0612 的回复:
[ForeignKey("tm_officialMatchGroupInfo")]
public string groupid { get; set; }

public string groupname { get; set; }

public DateTime createdate { get; set; }

public int matchid { get; set; }

public bool iseffective { get; set; } = false;

public virtual List<tm_officialMatchGroupInfo> tm_officialMatchGroupInfo { get; set; }

[ForeignKey("matchid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }

我是以groupid 做关联的
[ForeignKey("groudid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }
这么做后缺报错
调用c表 缺没有问题 为什么呢
正怒月神 版主 2018-08-13
  • 打赏
  • 举报
回复
[ForeignKey("tm_officialMatchGroupInfo")]
public string groupid { get; set; }

public string groupname { get; set; }

public DateTime createdate { get; set; }

public int matchid { get; set; }

public bool iseffective { get; set; } = false;

public virtual List<tm_officialMatchGroupInfo> tm_officialMatchGroupInfo { get; set; }

[ForeignKey("matchid")]
public virtual List<tm_officialMatchcode> tm_officialMatchcode { get; set; }
qq_30548569 2018-08-13
  • 打赏
  • 举报
回复
这么难吗22222222
aspnetmvc-nerdinner_v2.pdf 目 录 创建MVC Web Application ........................................................................................................................... 4 检查NerdDinner 项目的目录结构 ..................................................................................................... 5 运行NerdDinner 应用程序 ................................................................................................................. 8 测试NerdDinner 应用程序 ............................................................................................................... 10 创建数据库 ................................................................................................................................................ 10 设置之间的外键关系 ..................................................................................................................... 12 增加数据到Dinners 数据 ............................................................................................................... 13 创建Model 模型 ........................................................................................................................................ 13 LINQ to SQL ......................................................................................................................................... 14 控制器和视图(Controllers and Views) .................................................................................................. 25 添加DinnersController 控制器 .......................................................................................................... 25 理解ASP.NET MVC Routing ................................................................................................................. 27

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧