如何专门设置实体之间的关系 [英] How to specifically setup a relationship between entities

查看:80
本文介绍了如何专门设置实体之间的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在使用mvc5创建一个Web应用程序,该应用程序具有个人资料页面,图库和youtube页面。

现在,我已经设法通过自定义IdentityUser来构建配置文件页面.cs包括其他属性但我在画廊方面遇到困难。我已经建立了相当不错的课程,但我不知道如何设置它以我想要的方式工作。

我希望每个用户都有一个画廊页面所以我'我认为我仍然应该将其作为IdentityUser.cs中的属性添加,或者我应该将其设置为profile.cs的外键,如果是这样,我很难理解实体之间的关系。请,即使你想给我一个链接来增进我的理解,请帮助我构建我所解释的那种我需要的关系。请。我是c#的新手,也是网络应用的好人。



公共类画廊{

public int Id {get; set;}

public string Picture {get; set;}

public string Name {get; set}

public string说明{get; set;}

}

解决方案

看看这个。



使用Fluent API的代码优先方法实体框架中的关系

设置entiites之间的关系。你必须使用外键。



。外键是一个完成关系的属性识别父实体。


Hello, i am creating a web application using mvc5 that has a profile page, galleries, and youtube page.
Now, i have manage to construct that of the profile page by customizing the "IdentityUser.cs" to include additional properties but i am stuck when it comes to gallery aspect. I have the class built up quite alright but i don't know how to go about setting it up to work the way i want it to.
I want each user to have a gallery page so i'm thinking should i still add this as a property in "IdentityUser.cs" or should i set it as a foreignkey to profile.cs and if so i am having hard time understanding relationships between entities. Please, even if you want to give me a link to boost my understanding, kindly help me in constructing the kind of relationship i have explained that i need. Please. I am new to c# and its good in web apps.

Public class Galleries{
public int Id {get;set;}
public string Picture {get;set;}
public string Name {get;set}
public string Description {get;set;}
}

解决方案

Have a look at this one.

Relationship in Entity Framework Using Code First Approach With Fluent API


To set up relationship between entiites.You have to use foreign key.

.A foreign key is an attribute that completes a relationship by identifying the parent entity.


这篇关于如何专门设置实体之间的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆