如何解决一个表属性与两个表属性 .NET MVC
我有一个名为 News 的表,我想存储高质量和低质量的图像及其每个新图像的信息,因此我创建了另一个名为 NewsAttachment 的表这个表应该与 News 有关系,但我已经有另一个名为 NewsComment 的表,它也与 News 有关系,当我想同时定义两者时作为外键,sql Server 在 News 和 NewsAttachment 中添加另一列。
这是新闻课:
public class News
{
[Key]
public int NewsId { get; set; } //primary key
.
.
.
//navigation property
public virtual List<Comments> Comments { get; set; }
public virtual List<NewsAttachments> Comments { get; set; }
public News()
{
}
}
这是评论类:
public class Comments
{
[Key]
public int CommentId { get; set; }
[required]
public int NewsId { get; set; } //Foreign key of News
.
.
.
//navigation property
public virtual News News { get; set; }
public Comments()
{
}
}
这是NewsAttachment类:
public class NewsAttachment
{
[Key]
public int NewsAttachmentId { get; set; }
[required]
public int NewsId { get; set; } //Foreign key of News
//Image information property
public string FileName { get; set; }
public string RealFileName { get; set; }
public string FilePath { get; set; }
public string FilePageType { get; set; }
//navigation property
public News News { get; set; }
public NewsAttachment()
{
}
}
我的问题摘要: 我希望 News 中的 NewsId 与表中的其他两个属性有关系,但它遇到了麻烦。
如果无法解决这个问题,请给我另一种方法来将我的两张照片及其信息保存在我的数据库中。
解决方法
您必须专门向 EF 声明它,以便它知道哪个是外键:
import cv2
def track_ground():
b_min,g_min,r_min = 255,255,255
b_max,g_max,r_max = 0,0
##########################################
# mouse callback function
def get_pixel(event,x,y,flags,param):
nonlocal b_min,r_min,b_max,r_max
if event == cv2.EVENT_MOUSEMOVE:
b,g,r = img[x,y]
# We are moving around the mouse to find the range of values for rgb
# of the background; we will use them for thresholding later.
b_min = min(b,b_min)
g_min = min(g,g_min)
r_min = min(r,r_min)
b_max = max(b,b_max)
g_max = max(g,g_max)
r_max = max(r,r_max)
img = cv2.imread('test.jpg')
cv2.namedWindow('image')
cv2.setMouseCallback('image',get_pixel)
cv2.imshow('image',img)
while cv2.getWindowProperty('image',1) >= 0:
print(b_min,r_min)
print(b_max,r_max)
k = cv2.waitKey(30)
cv2.destroyAllWindows()
###########################################
return (b_min,r_min),(b_max,r_max)
print(track_ground())
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。