我正在研究ASP.NET MVC 5中的一個學校項目。該項目是關於創建一個社交網絡。用戶登錄後,他會在他的新聞源中看到所有公開帖子。 雖然我在顯示數據庫公開帖子的數據時遇到了問題。ASP.NET MVC 5 - LINQ查詢從數據庫中選擇數據
這是數據庫的腳本:
create table Utilizador(
id_utilizador integer not null identity(1,1),
nome varchar(50) not null,
apelido varchar(50) not null,
username varchar(15) not null unique,
pass varchar(50) not null,
email varchar(50) not null unique,
sexo char(1) not null CHECK (sexo IN('M', 'F')),
país varchar(50) not null,
imagem_perfil varchar(50) not null,
data_nascimento date not null,
estado int not null default 2, --0->Bloqueado 1-Activo, 2-por activar
primary key (id_utilizador),
check (email LIKE '%@%.%')
)
create table Post(
id_post integer not null identity(1,1),
texto varchar(400) not null,
primary key(id_post)
)
create table Publish_Post(
id_post integer not null,
id_utilizador integer not null,
data timestamp not null,
primary key(id_post),
foreign key(id_post) references Post(id_post),
foreign key(id_utilizador) references Utilizador(id_utilizador)
)
create table Privacy(
id_privacidade integer not null identity(1,1), --> 1 public, 2 private
nome varchar(50) not null,
primary key(id_privacidade)
)
create table Have_Privacy(
id_post integer not null,
id_privacidade integer not null,
primary key(id_post),
foreign key(id_post) references Post(id_post),
foreign key(id_privacidade) references Privacidade(id_privacidade)
)
讓我解釋一下爲什麼我創建數據庫我的方式: 用戶創建併發布一些帖子說有就有了隱私值(1或2)。用戶登錄後,所有公開帖子(1)應顯示在他的新聞源中。 到目前爲止,我有在C#這LINQ查詢:
var id_posts = from p in db.Posts
select p.texto;
ViewBag.Posts = id_posts;
有人能幫助我嗎? 感謝提前:)
感謝您對對策的探討,但後可以有很多類型的隱私:/ –
,但我需要有一個表只是爲了隱私,教授訂單 - 但是,無論如何,謝謝你:) –
我改變了一個查詢,所以它直接使用你的數據庫模式。現在有什麼問題?如果它解決了您的問題,請將其標記爲已回答。如果沒有,讓我知道它不符合什麼要求。 – mwilczynski