Menu

Entity Framework with Silverlight and WPF

ADO.NET ENTITY FRAMEWORK USING (SILVERLIGHT AND WCF)

The ADO.NET Entity Framework enables developers to create data access applications by programming against a conceptual application model instead of programming directly against a relational storage schema. The goal is to decrease the amount of code and maintenance required for data-oriented applications. Entity Framework applications provide the following benefits:

  1. Applications can work in terms of a more application-centric conceptual model, including types with inheritance, complex members, and relationships.
  2. Applications are freed from hard-coded dependencies on a particular data engine or storage schema.
  3. Mappings between the conceptual model and the storage-specific schema can change without changing the application code.
  4. Developers can work with a consistent application object model that can be mapped to various storage schemas, possibly implemented in different database management systems.
  5. Multiple conceptual models can be mapped to a single storage schema.
  6. Language-integrated query (LINQ) support provides compile-time syntax validation for queries against a conceptual model.
  7. Linq-To-Sql – use this framework if you plan on editing a one-to-one relationship of your data in your presentation layer.  Meaning you don’t plan on combining data from more than one table in any one view or page.
  8. Entity Framework – use this framework if you plan on combining data from more than one table in your view or page.

Getting Started

You need to have Silverlight 3.0 or 4.0 framework installed on your PC for implementation of  Entity Framework.
We can create Sliverlight application for Entity Framework.

Download Source Code:SilverlightApplication1.rar

  1. Create a new Silverlight application.  Open Visual Studio 2010 > File > New Project > Select the language (C# or VB.NET) > Select ‘Silverlight’ in the Project Types > from the templates, select Silverlight Navigation Application from the installed templates and enter a name for the
    application.

    1
  2. On clicking OK.
  3.  The next step is adding your entities to the project.  To do this, we’ll need to add a new file to our project which will contain the specifications for our entities.  Open up the Solution Explorer panel. Right-click on the name of your application (“SilverlightApplication1.Web”) and click on the option ‘Add’ >> ‘New Item’. Then, select ‘ADO.NET Entity Data Model’.
    2
  4. If there was already a database in place that you had to use, then you would select the ‘Generate from database’ option, and the Entity Framework would do its best to create models and associations that fit the data.  If you are starting an application from scratch and get to design the database, as I’ll be demonstrating in this walkthrough, select ‘Empty model.’ This is known as the model-first approach, instead of the database-first approach.

    3
  5. This will now open a new file –You start with an empty canvas.
    4
  6. Begin by adding you first entity.  To add an entity, right-click on the design surface (the white canvas area) and click “Add” >>”Entity” from the context menu.
    5
  7. The new entity you created will now appear on the design surface.  You can drag it around the designer as you please.

    6
  8. The next step will be to add properties to that entity.  Properties are essentially “instance data” in the lexicon of object-oriented programming or “columns” in database parlance.  You can add a property to an entity by right-clicking the entity and selecting ‘Add’ >> ‘Scalar Property’.  When you add the property, you can then name it whatever makes sense.
    5
  9. I will name the first one “First Name” – the First Name of the User.  When you have one of the properties highlighted – while renaming it – you can simply press the ‘Enter’ key to keep adding more.
    5
  10. Now create WCF service (“UserServiceDemo.svc”) to perform operation like (get user information, insert, update, delete).
    
    namespace SilverlightApplication1.Web
    
    {
    
    [ServiceContract(Namespace = "SilverlightApplication1.Web")]
    
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    
    public class UserServiceDemo
    
    {
    
    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
    
    // To create an operation that returns XML,
    
    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    
    //     and include the following line in the operation body:
    
    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    
    [OperationContract]
    
    public void DoWork()
    
    {
    
    // Add your operation implementation here
    
    return;
    
    }
    
    [OperationContract]
    
    public IList<User> GetUser()
    
    {
    
    var ctx = new UserModelEntityEntities();
    
    var query = from user in ctx.Users
    
    select user;
    
    return query.ToList();
    
    }
    
    [OperationContract]
    
    public int insertUser(string FirstName)
    
    {
    
    using (UserModelEntityEntities context = new UserModelEntityEntities())
    
    {
    
    User objUser = new User
    
    {
    
    First_Name = FirstName
    
    };
    
    context.Users.AddObject(objUser);
    
    context.SaveChanges();
    
    return 0;
    
    }
    
    }
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    [OperationContract]
    
    public int deleteUser(int ID)
    
    {
    
    using (UserModelEntityEntities context = new UserModelEntityEntities())
    
    {
    
    User userDelete = (from P in context.Users
    
    where P.Id == ID
    
    select P).FirstOrDefault();
    
    if (userDelete.Id > 0)
    
    {
    
    context.Users.DeleteObject(userDelete);
    
    context.SaveChanges();
    
    return 1;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    }
    
    else
    
    {
    
    return 0;
    
    }
    
    }
    
    }
    
    [OperationContract]
    
    public int updateUser(int ID, string FirstName)
    
    {
    
    using (UserModelEntityEntities context = new UserModelEntityEntities())
    
    {
    
    User user = (from P in context.Users
    
    where P.Id == ID
    
    select P).FirstOrDefault();
    
    user.First_Name = FirstName;
    
    context.SaveChanges();
    
    return 1;
    
    }
    
    }
    
    }
    
    }
    
    
  11. Now add service references in our “Silverlight Client side project”.
  12. You have code in your “xaml” file(home.xaml). Code like
    
    <navigation:Page x:Class="SilverlightApplication1.Home"
    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    
    Title="Home"
    
    Style="{StaticResource PageStyle}">
    
    <Grid x:Name="LayoutRoot">
    
    <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
    
    <StackPanel x:Name="ContentStackPanel">
    
    <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"
    
    Text="Home"/>
    
    <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}"
    
    Text="Home page content"/>
    
    <Button x:Name="RefreshButton" Click="RefreshButton_Click">
    
    Refreh
    
    </Button>
    
    <ListBox x:Name="lbProducts" Height="122" HorizontalAlignment="Left"
    
    VerticalAlignment="Bottom" Margin="10,10,10,10" Width="154"
    
    ItemsSource="{Binding}" SelectionChanged="lbProducts_SelectionChanged"
    
    SelectionMode="Single" SelectedValuePath="Id">
    
    <ListBox.ItemTemplate>
    
    <DataTemplate>
    
    <StackPanel Orientation="Horizontal">
    
    <TextBlock Text="{Binding First_Name}" />
    
    </StackPanel>
    
    </DataTemplate>
    
    </ListBox.ItemTemplate>
    
    </ListBox>
    
    <StackPanel Orientation="Horizontal">
    
    <TextBlock Height="23" Name="textBlock1" Text="First Name"  Width="150"/>
    
    <TextBox Height="23" Name="textBox1" Width="120" />
    
    <TextBlock Height="23" Name="textID" Text="Id"  Width="150"/>
    
    </StackPanel>
    
    <Button Content="Submit" Height="23"
    
    Name="button1" Width="75" Click="button1_Click" />
    
    <Button Content="Delete" Height="23"
    
    Name="button2" Width="75" Click="button2_Click" />
    
    <Button Content="Update" Height="23"
    
    Name="button3" Width="75" Click="button3_Click" />
    
    </StackPanel>
    
    </ScrollViewer>
    
    </Grid>
    
    </navigation:Page>
    
    
  13.  You have code in your “xaml.cs” file(Home.xaml.cs). Code like
    
    public partial class Home : Page
    
    {
    
    ServiceReference2.UserServiceDemoClient _proxy = null;
    
    public Home()
    
    {
    
    InitializeComponent();
    
    this.Loaded += new RoutedEventHandler(Page_Loaded);
    
    }
    
    void Page_Loaded(object sender, RoutedEventArgs e)
    
    {
    
    _proxy = new ServiceReference2.UserServiceDemoClient();
    
    #region Simple
    
    _proxy.GetUserCompleted += new EventHandler<ServiceReference2.GetUserCompletedEventArgs>(_proxy_GetPeopleCompleted);
    
    _proxy.insertUserCompleted += new EventHandler<ServiceReference2.insertUserCompletedEventArgs>(_proxy_insertUserRecord);
    
    _proxy.deleteUserCompleted += new EventHandler<ServiceReference2.deleteUserCompletedEventArgs>(deleteRecord);
    
    _proxy.updateUserCompleted += new EventHandler<ServiceReference2.updateUserCompletedEventArgs>(updateRecord);
    
    #endregion
    
    _proxy.GetUserAsync();
    
    }
    
    // Executes when the user navigates to this page.
    
    protected override void OnNavigatedTo(NavigationEventArgs e)
    
    {
    
    }
    
    void _proxy_GetPeopleCompleted(object sender,
    
    ServiceReference2.GetUserCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    lbProducts.ItemsSource = e.Result;
    
    lbProducts.SelectedValuePath = "Id";
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message);
    
    }
    
    }
    
    void _proxy_insertUserRecord(object sender,
    
    ServiceReference2.insertUserCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    MessageBox.Show(e.Result.ToString());
    
    _proxy.GetUserAsync();
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message);
    
    }
    
    }
    
    void deleteRecord(object sender, ServiceReference2.deleteUserCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    int result = e.Result;
    
    if (result == 1)
    
    {
    
    MessageBox.Show("Deleted");
    
    _proxy.GetUserAsync();
    
    }
    
    else
    
    {
    
    MessageBox.Show("Not Deleted");
    
    }
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message);
    
    }
    
    }
    
    void updateRecord(object sender, ServiceReference2.updateUserCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    int result = e.Result;
    
    MessageBox.Show(result.ToString());
    
    _proxy.GetUserAsync();
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message.ToString());
    
    }
    
    }
    
    private void RefreshButton_Click(object sender, RoutedEventArgs e)
    
    {
    
    _proxy.GetUserAsync();
    
    }
    
    //Insert Record in database
    
    private void button1_Click(object sender, RoutedEventArgs e)
    
    {
    
    _proxy.insertUserAsync(textBox1.Text);
    
    }
    
    //list box selection change event
    
    private void lbProducts_SelectionChanged(object sender, SelectionChangedEventArgs e)
    
    {
    
    if (lbProducts.SelectedValue != null)
    
    {
    
    ListBoxItem item = this.lbProducts.ItemContainerGenerator.ContainerFromIndex(lbProducts.SelectedIndex)
    
    as ListBoxItem;
    
    TextBlock tagregCheckBox = FindFirstElementInVisualTree<TextBlock>(item);
    
    textBox1.Text = tagregCheckBox.Text;
    
    textID.Text = lbProducts.SelectedValue.ToString();
    
    }
    
    }
    
    //delete user information
    
    private void button2_Click(object sender, RoutedEventArgs e)
    
    {
    
    if (lbProducts.SelectedValue != null)
    
    _proxy.deleteUserAsync (Convert.ToInt32(lbProducts.SelectedValue));
    
    }
    
    //Find child node from list box
    
    private T FindFirstElementInVisualTree<T>(DependencyObject parentElement) where T : DependencyObject
    
    {
    
    var count = VisualTreeHelper.GetChildrenCount(parentElement);
    
    if (count == 0)
    
    return null;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    for (int i = 0; i < count; i++)
    
    {
    
    var child = VisualTreeHelper.GetChild(parentElement, i);
    
    if (child != null &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp; child is T)
    
    {
    
    return (T)child;
    
    }
    
    else
    
    {
    
    var result = FindFirstElementInVisualTree<T>(child);
    
    if (result != null)
    
    return result;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    }
    
    }
    
    return null;
    
    }
    
    //update information
    
    private void button3_Click(object sender, RoutedEventArgs e)
    
    {
    
    _proxy.updateUserAsync(Convert.ToInt32(textID.Text), textBox1.Text);
    
    }
    
    }
    
    

ENTITY FRAMEWORK WITH (STORE PROCEDURE AND VIEW)

  1. Select your Entity Framework (.edmx) file in Solution Explorer. right-click on the design surface and click “Update Model from database.”

    5
  2. Select your database and click on next. when you update the database model, you are presented with a dialog to choose the database items to add to your model.
    5
  3. Once you click Finish, the model will be read and the dialog will close. Now, you might think, what the heck? Nothing seems to happen. But basically here you have just told Entity Framework about your stored procedure. But to actually get it hooked up to the context so you can call it, you need to Import the stored procedure as a Function. Right-click on the workspace area of your Entity model and choose Add -> Function Import.
    5
  4. In the Add Function Import dialog, enter the name you want your stored procedure to be referred to in your model, choose your procedure from the drop down list, and choose the return value of the procedure to be Scalar in this case. (Import your all procedure like)
    5
  5. Now you can call this method using code like this:
  6. Now implement WCF service (“UserServiceDemo.svc”) to perform operation like (get user information, insert, update, delete) using store procedure and view. Get more information about WCF service’s click here
    
    [ServiceContract(Namespace = "SilverlightApplication1.Web")]
    
    [AspNetCompatibilityRequirements(RequirementsMode =
    
    AspNetCompatibilityRequirementsMode.Allowed)]
    
    public class UserServiceDemo
    
    {
    
    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is
    
    WebMessageFormat.Json)
    
    // To create an operation that returns XML,
    
    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    
    //     and include the following line in the operation body:
    
    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    
    [OperationContract]
    
    public IList<getUserInfo1> GetUserWithVW()                //Get user information using view
    
    {
    
    var ctx = new UserModelEntityEntities();
    
    var query = (from use in ctx.getUserInfo1
    
    select use);
    
    return query.ToList();
    
    }
    
    [OperationContract]
    
    public int addUserWithSP(string FirstName) //insert user information using store procedure
    
    {
    
    using (UserModelEntityEntities context = new UserModelEntityEntities())
    
    {
    
    context.AddUserInformation(FirstName);
    
    return 0;
    
    }
    
    }
    
    [OperationContract]
    
    public int deleteUserSP(int ID) //delete user information using store procedure
    
    {
    
    using (UserModelEntityEntities context = new UserModelEntityEntities())
    
    {
    
    context.DeleteUserInformation(ID);
    
    context.SaveChanges();
    
    return 1;
    
    }
    
    }
    
    [OperationContract] //update user information using store procedure
    
    public int updateUserSP(int ID, string FirstName)
    
    {
    
    using (UserModelEntityEntities context = new UserModelEntityEntities())
    
    {
    
    context.UpdateUserInformation(ID, FirstName);
    
    context.SaveChanges();
    
    return 1;
    
    }
    
    }
    
    }
    
    
  7. Now add service references in our “Silverlight Client side project”.
  8. You have code in your “xaml” file(home.xaml). Code like
    
    <navigation:Page x:Class="SilverlightApplication1.Home"
    
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"
    
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    
    Title="Home"
    
    Style="{StaticResource PageStyle}">
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    <Grid x:Name="LayoutRoot">
    
    <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    <StackPanel x:Name="ContentStackPanel">
    
    <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"
    
    Text="Home"/>
    
    <TextBlock x:Name="ContentText" Style="{StaticResource ContentTextStyle}"
    
    Text="Home page content"/>
    
    <Button x:Name="RefreshButton" Click="RefreshButton_Click">
    
    Refreh
    
    </Button>
    
    <ListBox x:Name="lbProducts" Height="122" HorizontalAlignment="Left"
    
    VerticalAlignment="Bottom" Margin="10,10,10,10" Width="154"
    
    ItemsSource="{Binding}" SelectionChanged="lbProducts_SelectionChanged"
    
    SelectionMode="Single" SelectedValuePath="Id">
    
    <ListBox.ItemTemplate>
    
    <DataTemplate>
    
    <StackPanel Orientation="Horizontal">
    
    <TextBlock Text="{Binding First_Name}" />
    
    </StackPanel>
    
    </DataTemplate>
    
    </ListBox.ItemTemplate>
    
    </ListBox>
    
    <StackPanel Orientation="Horizontal">
    
    <TextBlock Height="23" Name="textBlock1" Text="First Name"  Width="150"/>
    
    <TextBox Height="23" Name="textBox1" Width="120" />
    
    <TextBlock Height="23" Name="textID" Text="Id"  Width="150"/>
    
    </StackPanel>
    
    <Button Content="Submit" Height="23"
    
    Name="button1" Width="75" Click="button1_Click" />
    
    <Button Content="Delete" Height="23"
    
    Name="button2" Width="75" Click="button2_Click" />
    
    <Button Content="Update" Height="23"
    
    Name="button3" Width="75" Click="button3_Click" />
    
    </StackPanel>
    
    </ScrollViewer>
    
    </Grid>
    
    </navigation:Page>
    
    
  9. You have code in your “xaml.cs” file(Home.xaml.cs). Code like
    
    public partial class Home : Page
    
    {
    
    ServiceReference2.UserServiceDemoClient _proxy = null;
    
    public Home()
    
    {
    
    InitializeComponent();
    
    this.Loaded += new RoutedEventHandler(Page_Loaded);
    
    this.DataContext = this;
    
    }
    
    void Page_Loaded(object sender, RoutedEventArgs e)
    
    {
    
    _proxy = new ServiceReference2.UserServiceDemoClient();
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    #region using store procedure
    
    _proxy.updateUserSPCompleted += new EventHandler<ServiceReference2.updateUserSPCompletedEventArgs>(updateRecordWithSP);
    
    _proxy.addUserWithSPCompleted += new EventHandler<ServiceReference2.addUserWithSPCompletedEventArgs>(_proxy_insertUserRecordWithSP);
    
    _proxy.deleteUserSPCompleted += new EventHandler<ServiceReference2.deleteUserSPCompletedEventArgs>(deleteRecordWitsSP);
    
    _proxy.GetUserWithVWCompleted += new EventHandler<ServiceReference2.GetUserWithVWCompletedEventArgs>(_proxy_GetPeopleVWCompleted);
    
    #endregion
    
    _proxy.GetUserWithVWAsync();
    
    }
    
    // Executes when the user navigates to this page.
    
    protected override void OnNavigatedTo(NavigationEventArgs e)
    
    {
    
    }
    
    void _proxy_GetPeopleVWCompleted(object sender,
    
    ServiceReference2.GetUserWithVWCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    //UserInfo = e.Result;
    
    //ObservableCollection<ServiceReference2.User> listboxObc = e.Result;
    
    //if (lbProducts.Items.Count > 0)
    
    //{
    
    //    //for (int val = 0; val <= lbProducts.SelectedItems.Count - 1; val++)
    
    //    //{
    
    //    //    lbProducts.Items.Remove(lbProducts.SelectedItems[val]);
    
    //    //}
    
    //    lbProducts.SelectedIndex = 0;
    
    //}
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    ////lbProducts.Dispatcher.BeginInvoke(() => { lbProducts.Items.Clear(); });
    
    lbProducts.ItemsSource = e.Result;
    
    ////lbProducts.DisplayMemberPath = "First_Name";
    
    lbProducts.SelectedValuePath = "Id";
    
    ////lbProducts.SelectedValue = "First_Name";
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message);
    
    }
    
    }
    
    void _proxy_insertUserRecordWithSP(object sender,
    
    ServiceReference2.addUserWithSPCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    MessageBox.Show(e.Result.ToString());
    
    //_proxy.GetUserAsync();
    
    _proxy.GetUserWithVWAsync();
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message);
    
    }
    
    }
    
    void deleteRecordWitsSP(object sender, ServiceReference2.deleteUserSPCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    int result = e.Result;
    
    if (result == 1)
    
    {
    
    MessageBox.Show("Deleted");
    
    //_proxy.GetUserAsync();
    
    _proxy.GetUserWithVWAsync();
    
    }
    
    else
    
    {
    
    MessageBox.Show("Not Deleted");
    
    }
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message);
    
    }
    
    }
    
    void updateRecordWithSP(object sender, ServiceReference2.updateUserSPCompletedEventArgs e)
    
    {
    
    try
    
    {
    
    int result = e.Result;
    
    MessageBox.Show(result.ToString());
    
    _proxy.GetUserWithVWAsync();
    
    }
    
    catch (Exception ex)
    
    {
    
    MessageBox.Show(ex.Message.ToString());
    
    }
    
    }
    
    private void RefreshButton_Click(object sender, RoutedEventArgs e)
    
    {
    
    _proxy.GetUserWithVWAsync();
    
    }
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    private void button1_Click(object sender, RoutedEventArgs e)
    
    {
    
    _proxy.addUserWithSPAsync(textBox1.Text);
    
    }
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    private void lbProducts_SelectionChanged(object sender, SelectionChangedEventArgs e)
    
    {
    
    if (lbProducts.SelectedValue != null)
    
    {
    
    ListBoxItem item =
    
    this.lbProducts.ItemContainerGenerator.ContainerFromIndex(lbProducts.SelectedIndex) as ListBoxItem;
    
    TextBlock tagregCheckBox = FindFirstElementInVisualTree<TextBlock>(item);
    
    textBox1.Text = tagregCheckBox.Text;
    
    if (lbProducts.SelectedValue != null)
    
    textID.Text = lbProducts.SelectedValue.ToString();
    
    }
    
    }
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    private void button2_Click(object sender, RoutedEventArgs e)
    
    {
    
    if (lbProducts.SelectedValue != null)
    
    _proxy.deleteUserSPAsync(Convert.ToInt32(lbProducts.SelectedValue));
    
    }
    
    private T FindFirstElementInVisualTree<T>(DependencyObject parentElement) where T : DependencyObject
    
    {
    
    var count = VisualTreeHelper.GetChildrenCount(parentElement);
    
    if (count == 0)
    
    return null;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    for (int i = 0; i < count; i++)
    
    {
    
    var child = VisualTreeHelper.GetChild(parentElement, i);
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    if (child != null &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp; child is T)
    
    {
    
    return (T)child;
    
    }
    
    else
    
    {
    
    var result = FindFirstElementInVisualTree<T>(child);
    
    if (result != null)
    
    return result;
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    }
    
    }
    
    return null;
    
    }
    
    &amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;amp;nbsp;
    
    private void button3_Click(object sender, RoutedEventArgs e)
    
    {
    
    _proxy.updateUserSPAsync(Convert.ToInt32(textID.Text), textBox1.Text);
    
    }
    
    }
    
    

    Referral Links:=>

    http://blogs.msdn.com/b/adonet/archive/2010/07/19/absolue-beginners-guide-to-entity-framework.aspx

    http://manaspatnaik.com/blog/index.php/technology/silverlight-4/step-by-step-guide-to-wcf-ria-enabled-sl4-application-with-entity-framework/404#comment-759

    http://blogs.msdn.com/b/dsimmons/archive/2008/05/17/why-use-the-entity-framework.aspx

    http://www.dofactory.com/topic/1077/when-to-use-linq-to-sql-versus-entity-framework.aspx

    http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

    http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

No comments

Leave a Reply


× 2 = 10

Categories