[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How create this view in sql server?

Posted on 2015-01-14
4
Medium Priority
?
76 Views
Last Modified: 2015-01-16
I need to create an view in sql server. I do this easily but this one is a little bit more complicated than I can do.
I have two tables.  

   [Table("PERSONS")]
    public partial class PERSON
    {
        public PERSON()
        {
            Movs = new HashSet<Mov>();
            Movs1 = new HashSet<Mov>();
        }

        public int PersonID { get; set; }

        [Required]
        [StringLength(50)]
        public string PersonName { get; set; }

        public virtual ICollection<Mov> Movs { get; set; }

        public virtual ICollection<Mov> Movs1 { get; set; }
    }

    public partial class Mov
    {
        public int MovID { get; set; }

        public int PersonID { get; set; }

        public int OtherPersonID { get; set; }

        public virtual PERSON PERSON { get; set; }

        public virtual PERSON PERSON1 { get; set; }
    }

and the context is:

 public partial class Model1 : DbContext
    {
        public Model1()
            : base("name=Model1")
        {
        }

        public virtual DbSet<Mov> Movs { get; set; }
        public virtual DbSet<PERSON> PERSONS { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<PERSON>()
                .Property(e => e.PersonName)
                .IsUnicode(false);

            modelBuilder.Entity<PERSON>()
                .HasMany(e => e.Movs)
                .WithRequired(e => e.PERSON)
                .HasForeignKey(e => e.PersonID)
                .WillCascadeOnDelete(false);

            modelBuilder.Entity<PERSON>()
                .HasMany(e => e.Movs1)
                .WithRequired(e => e.PERSON1)
                .HasForeignKey(e => e.OtherPersonID)
                .WillCascadeOnDelete(false);
        }
    }



i need a view with both names.

how could I do that?
0
Comment
Question by:Deraldo Silva
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 11

Expert Comment

by:Ray
ID: 40550194
If you get no other response, you should really consider adding this to one of the programming topics.  Most people in this topic (SQL) don't tend to speak sql in terms of developer coding (a few do though).
0
 

Author Comment

by:Deraldo Silva
ID: 40550222
Ok.
i have this relation in the db.
i need a view with both names.

thx for your attention
relation.png
0
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 2000 total points
ID: 40554067
CREATE VIEW MovsView
AS
SELECT MovID, P.PersonName, OP.PersonName AS OtherPersonName
FROM Movs M
JOIN Persons P ON M.PersonID = P.PersonID
JOIN Persons OP ON M.OtherPersonID = OP.PersonID

Note: You may use left join, if personids can be NULL in Movs table.

HTH.
0
 

Author Closing Comment

by:Deraldo Silva
ID: 40554124
Thx
0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question