Answer the question
In order to leave comments, you need to log in
Multiple items in an ASP.NET DB cell?
There are 3 tables:
CREATE TABLE [dbo].[Users] (
[Id] INT NOT NULL,
[Login] NVARCHAR (20) NOT NULL,
[Password] NVARCHAR (20) NOT NULL,
[FirstName] NVARCHAR (15) NOT NULL,
[SurName] NVARCHAR (15) NOT NULL,
[LastName] NVARCHAR (15) NULL,
[Status] NVARCHAR (15) NOT NULL,
[Balance] INT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[MoneyTrancfer] (
[Id] INT NOT NULL,
[UserID] INT NOT NULL,
[Amount] INT NOT NULL,
[Title] NVARCHAR (150) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
CREATE TABLE [dbo].[Event]
(
[Id] INT NOT NULL PRIMARY KEY,
[Name] NVARCHAR(50) NOT NULL,
[Reward] INT NOT NULL,
[Вescription] NVARCHAR(150) NULL,
[Amount] TINYINT NOT NULL,
[EndTime] DATETIME NOT NULL
)
Answer the question
In order to leave comments, you need to log in
1. How to make a link in the table to User? (Replace UserID)
select Users.LastName, MoneyTrancfer.Amount
from MoneyTrancfer join Users on (MoneyTrancfer.UserID=Users .id)
It's hard to know exactly what you want. You better tell the problem itself.
In which table do you need to make a link to the user? UserID is a link, why replace it?
What does it mean to make several users in one cell? Do you mean one-to-many or many-to-many relationship? It is not clear which table you want to associate with which and which relationship.
You show a DB, and you probably through EF do, show models. Or do you need to show the models in the code how they will look? In general, nothing is clear)
From the comments, I understand that you want to know how the models will look in the code for EF. And once again looking at your tables, I realized that you did not compose them quite correctly. In the User
tablethe Balance field was supposed to point to the Balance table . In this case, it should have been called BalanceId. But again, only for cases where the user can have only one balance. Then in the Balance table it was not necessary to point to the user UserId.
I roughly threw in how it would be in C #
public class User
{
public int Id { get; set; }
public string Login { get; set; }
public string Password { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual IEnumerable<Event> Events { get; set; }
public virtual IEnumerable<Balance> Balances { get; set; }
public User()
{
Events = new List<Event>();
Balances = new List<Balance>();
}
}
public class Event
{
public int Id { get; set; }
public string Name { get; set; }
public DateTime EndTime { get; set; }
public virtual IEnumerable<User> Users { get; set; }
public Event()
{
Users = new List<User>();
}
}
public class Balance
{
public int Id { get; set; }
public decimal Amount { get; set; }
public int UserId { get; set; }
public virtual User User { get; set; }
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question