views:

297

answers:

3
+1  Q: 

linq error

Hi

I am working on a mobile.net project. I am trying to make a list of restaurants which is displayed in a drop down list...whn d user selects an item he can add it to d list of favorites. However i am getting an error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0102: The type 'mobile_rest' already contains a definition for 'emptyChangingEventArgs'

Source Error:

Line 78: {
Line 79:    
Line 80:    private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
Line 81:    
Line 82:    private int _r_id;

I have no clue why this is happening... is it because i used d same table in another file too?

Here is my code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Favorite.aspx.cs" Inherits="Favorite" %>
<%@ Register TagPrefix="mobile" Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form id="Form1" runat="server" BackColor="#fcf9f3" Method="get" Paginate="True">

        <mobile:Label ID="FaveError" Runat="server" ForeColor="red" 
            Font-Size="Small" Font-Bold="True" Visible="false" />

        <mobile:Label ID="Label2" Runat="server" ForeColor="#d3af63" Font-Italic="True" 
                Font-Name="Monotype Covasia" Font-Bold="True" text="Choose Favorite's" />

        <mobile:SelectionList ID="listSearch" Runat="server" DataTextfield="r_name"
                 DataValueField="r_name" BreakAfter="False">

        </mobile:SelectionList>

        <mobile:Command ID="btnadd" text="Add" Runat="server" OnClick="btn_add_Click" />

        <mobile:list runat="server" id="ListFavorite" DataTextfield="fave_name"
             DataValueField="user_id" Font-Size="Small" Font-Italic="True" 
             Wrapping="Wrap"  BreakAfter="True"/>
            <mobile:Command ID="btndelete" text="Delete" Runat="server" OnClick="btn_delete_Click" />

    </mobile:Form>
</body>
</html>

And code behind

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Mobile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.MobileControls;
using System.Data.Linq;
using System.Xml.Linq;
using System.Linq;

public partial class Favorite : System.Web.UI.MobileControls.MobilePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["error_msg"] != null)
        {
            FaveError.Text = Session["error_msg"].ToString();
            Session["error_msg"] = null;
            FaveError.Visible = true;
        }

        //if (Session["user_id"] = null)
        //{
        //    Response.Redirect("Login.aspx");
        //}
        GetRstr();
        GetFave();
    }

    protected void btn_add_Click(object sender, EventArgs e)
    {
        if (Page.IsValid) // only valid page will proceed
        {
            AddFave();
        }
    }

    #region add fave
    protected void AddFave()
    {
        String faveitem = listSearch.SelectedIndex;

        using (FavoriteDataContext Favorite = new FavoriteDataContext())
        {
            mobile_favorite mobilefave = new mobile_favorite();
            mobilefave.fave_name = faveitem;
            mobilefave.user_id = Int32.Parse(Session["user_id"].ToString());
            mobilefave.username = Session["user_name"].ToString();

            Favorite.mobile_favorites.InsertOnSubmit(mobilefave);
            Favorite.SubmitChanges();

            Session["error_msg"] = "You have a new favorite";
            Response.Redirect("Favorite.aspx");
        }
    }
    #endregion


    protected void btn_delete_Click(object sender, EventArgs e)
    {
        if (Page.IsValid) // only valid page will proceed
        {
            DeleteFave();
        }
    }

    #region del fave
    protected void DeleteFave()
        {
            int iuser_id = Int32.Parse(Session["user_id"].ToString());
            using (FavoriteDataContext Favorite = new FavoriteDataContext())
            {
                try
                {
                    mobile_favorite fave = Favorite.mobile_favorites.Single(f => f.user_id == iuser_id);

                    Favorite.mobile_favorites.DeleteOnSubmit(fave);
                    Favorite.SubmitChanges();
                }
                catch (Exception ex)
                {
                }
            }
        }
    #endregion


    protected void GetFave()
    {
        using (FavoriteDataContext Favorite = new FavoriteDataContext())
        {
            var fave = from f in Favorite.mobile_favorites
                      // where f.user_id == Int32.Parse(Session["user_id"].ToString())
                       select f;

            ListFavorite.DataSource = fave;
            ListFavorite.DataBind();
        }
    }

    protected void GetRstr()
    {
        using (Restaurant2DataContext Restaurant2 = new Restaurant2DataContext())
        {
            var rstr = from r in Restaurant2.table_rests
                       select r;

            listSearch.DataSource = rstr;
            listSearch.DataBind();
        }
    }
}

mobile_rest is the table name

Thanks

+1  A: 

You have 2 or more emptyChangingEventArgs declared. It's pretty obvious from the error message.

Richard Hein
+1  A: 

If "mobile_rest" is a database table name and you're using the standard VS2008 tools to create your LINQ-based classes, then I guess you've also got a partial class also named "mobile_rest." Do you accidentally have this type declaring emptyChangingEventArgs in multiple places? Just use the search functionality within VS and see how many times this static field is declared.

Chris Farmer
A: 

I fixed the error. It happened bcoz i used d same table in more than 1 linq files. So was clashing. Thanks for taking d time out to reply though.