0

i have used Store Stored Procedure in my database (SQL Server)

select namebuffet,namefamilymember,idmember,Sum(finalpricefactorbuffet)-Sum((delivery*30)/100) as Price from Buffet_factorbuffet
 Inner join Buffet_buffet
 on idbuffet=buffetidfactor
 Inner join Member_member
 on idmember=memberid
 inner join Buffet_banktransaction
 on factorid=idfactorbuffet
 where success=1 And checkout!=2 And datecheckouted is null
 GROUP BY namebuffet,namefamilymember,idmember

Then i imported this in my WPF project with entity framework and also wrote my class like this

    public class Buffetinformation
        public List<Windows_BuffetInformation_Result> Getbuffetinformation ()
{
            using (MYDBEntities DB = new MYDBEntities())

                    var q = DB.Windows_BuffetInformation().AsQueryable();
                    return q.ToList();
}

how can i bind some parts to datagridview controller using above class ,my stored procedure return some columns like (namebuffet,nameandfamilly,idmember and ....) but i want to use only namebuffet and idmember and show them in my datagridview or another controllers

i have seen some examples using ado.net but i cant find examples of entity framework

2
  • 1
    First off watch out with your using statement. Without the curly braces ({ ... }) only the next line of code will be execute as inside it. Meaning that your Code right now wouldn't event compile as on the line with the return the variable q is not declared Commented Dec 10, 2018 at 13:40
  • Possible duplicate of Entity Framework & WPF Datagrid binding Commented Dec 10, 2018 at 16:29

2 Answers 2

0

To bind data to DataGrid you just bind your resulting list to DataGrid ItemsSource property. Showing only some parts is mostly about setting up datagrid in XAML. Firstly, in definition of your DataGrid you should set AutoGenerateColumns to False. Then you should define a DataGrid.Columns and make an explicit definition for each column. Something like this:

<DataGrid Name=MyDataGrid AutoGenerateColumns=False>
    <DataGrid.Columns>
        <DataGridTextColumn Header="Id" Binding="{Binding idmember}"/>
        <DataGridTextColumn Header="Name" Binding="{Binding namebuffet}"/>
    </DataGrid.Columns>
</DataGrid>
Sign up to request clarification or add additional context in comments.

Comments

0

You could potentially bind directly to your model objects. Bind the itemssource of a datagrid to a public property Observablecollection in a viewmodel which implements inotifypropertychanged.

An observablecollection can take a List in it's constructor. You have a List there from your ToList(). So you could use that to set your property to a new observablecollection from that list you generate.

That would be a very basic approach because you have nowhere to put logic. More usual would be to iterate the model instances and new up a row viewmodel, copy the properties across. I usually use reflection to copy matching properties.

But if you just want a "get you started".

https://social.technet.microsoft.com/wiki/contents/articles/28209.wpf-entity-framework-mvvm-walk-through-1.aspx?Redirected=true

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.