C
C
cats722017-06-13 17:37:05
ASP.NET
cats72, 2017-06-13 17:37:05

How to pull data from ASP.NET database?

There is a database, it has 3 tables:
Teams:
99716b2345ac49138cff72210a192170.jpg
Players:
52c03275f59e4b9ea453e6cbb5a8299b.jpg
And transfers:
af9a46f423c3424eac0da564f97a7a01.jpg
How to display a 3rd table so that instead of TeamId and PlayerId there are names and names of teams?
Models

Players

public partial class Players
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Players()
{
Transfers = new HashSet();
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int PlayerId { get; set; }
[StringLength(50)]
public string namePlayer { get; set; }
public int? numberOfMatchesPlayed { get; set; }
public int? numberOfYellowCards { get; set; }
public int? numberOfRedCards { get; set; }
public int? numberOfgoalsScored { get; set; }
public int? playerCoefficient { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection Transfers { get; set; }
}
Teams

public partial class Teams
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Teams()
{
Transfers = new HashSet();
}
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int TeamId { get; set; }
[StringLength(30)]
public string nameClub { get; set; }
public int? numberOfgames { get; set; }
public int? Won { get; set; }
public int? equalityOfPoints { get; set; }
public int? defeat { get; set; }
public int? hammeredBalls { get; set; }
public int? missedBalls { get; set; }
public int? goalDifference { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection Transfers { get; set; }
}
Transfers

public partial class Transfers
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int TransfId { get; set; }
public int? TeamId { get; set; }
public int? PlayerId { get; set; }
[Column(TypeName = "money")]
public decimal? CostPlayer { get; set; }
public DateTime? DateTransfer { get; set; }
public DateTime? DateOut { get; set; }
public virtual Players Players { get; set; }
public virtual Teams Teams { get; set; }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2017-06-13
@tsklab

How to display the 3rd table so that instead of TeamId and PlayerId there are names and names of teams?
Use linking by key fields.

R
Rifat, 2017-06-14
@serber

Use JOIN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question