Denormalizing entities for binding to a grid?

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I've got two tables in SQL Server, say A and B. B is a list of documents, and A contains data indicating whether a project should include a row in B.

A
___________
AId int PK,
BId int,
Include bit

B
___________
BId int PK,
BDocNumber varchar(10),
BName varchar(128)

I have POCOs for A and B, but ultimately what I'm after is something I can bind to a devExpress grid that contains the data from both (BDocNumber, BName, Include)

  1. I can set up B as a navigation property, but I don't know a way to flatten that out for the grid (DevExpress ASPxGridView, server mode)

  2. I've also looked into entity splitting, but it appears that won't work since I want to join on BId instead of AId.

A solution to either 1 or 2 is acceptable, but learning about both would be awesome.

Thanks

profilepic.png
manpreet 2 years ago

 

What you have is a "has-a" relationship or a one-to-one navigation b.com/tag/property">property in A to B that you want to access in your DevExpress Grid. You can do this by b.com/tag/set">setting your FieldName b.com/tag/property">property to your NavigationProperty.FieldName

Say for a one-to-one relationship of Persont to Address like the following:

    public class Person
    {

      public int ID { get; b.com/tag/set">set; }
      public string FirstName { get; b.com/tag/set">set; }
      public string LastName { get; b.com/tag/set">set; }
      public virtual Address Address { get; b.com/tag/set">set; }
    }

    public class Address
    {
      public int ID { get; b.com/tag/set">set; }
      public string StreetAddress { get; b.com/tag/set">set; }
      public string City { get; b.com/tag/set">set; }
      public string State { get; b.com/tag/set">set; }
      public string Zip { get; b.com/tag/set">set; }

     }

Your GridView in your aspx b.com/tag/page">page to include both the Person and the StreeAddress b.com/tag/property">property of the Address navigation b.com/tag/property">property would look like this

        <dx:ASPxGridView ID="ASPxGridView1" runat="server">
        <Columns>
            <dx:GridViewDataTextColumn FieldName="FirstName" VisibleIndex="0">
            dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="LastName" VisibleIndex="1">
            dx:GridViewDataTextColumn>
            <dx:GridViewDataTextColumn FieldName="Address.StreetAddress" VisibleIndex="1">
            dx:GridViewDataTextColumn>
        Columns>
    dx:ASPxGridView>

In this case, Person being table A and Address being table B. You are binding your gridview on A so then you would be b.com/tag/set">setting your field name to B.FieldToDisplay.

Hope this helps!


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.