3

I have following code:

   public static bool Update(UserExtendedData data, byte[] image)
        {

            data.UserId = getUserId_new();

            IQueryable<UserExtendedData> entry = m_model.UserExtendedDataSet.Where(x => x.UserId == getUserId_new());
            UserExtendedData User = entry.Single();
            User.firstName = data.firstName;
            User.lastName = data.lastName;
            User.phoneNo = data.phoneNo;
            User.creditCardNo = data.creditCardNo;
            User.dateOfBirth = data.dateOfBirth;
            User.UserId = getUserId_new();

            if (image != null)
            {
                User.avatarArt = image;
            }
            m_model.UserExtendedDataSet.InsertOnSubmit(data);

            return true;
        }

I have include using System.Data.Linq; i'm using asp.net 4.5 on windows 7 (x64) i also include:

 <compilation debug="true" targetFramework="4.5">

but i still got error:

does not contain a definition for 'InsertOnSubmit' and no extension method 'InsertOnSubmit' accepting a first argument of type ' could be found (are you missing a using directive or an assembly reference?) 

But what is weird i got no problems with:

public static bool Insert(UserExtendedData data, byte[] image)
        {

            data.UserId = getUserId_new();

                if (image != null)
                    data.avatarArt = image;

                m_model.UserExtendedDataSet.Add(data) ;
                m_model.SaveChanges();
                return true;
        }

Do you have any ideas what could cause this problem ? I will really appreciate any help.

Gert Arnold
  • 105,341
  • 31
  • 202
  • 291
molu2008
  • 1,237
  • 2
  • 15
  • 20
  • Are you using `Namespace: System.Data.Linq`? – Amit Dec 10 '13 at 06:54
  • I only have: using System.Data.Linq; do i have using namespace ? – molu2008 Dec 10 '13 at 06:55
  • Please check Entity database should be dbml file not the dbmx file. – Amit Dec 10 '13 at 06:57
  • I do not understand fully what you mean, i using external db. – molu2008 Dec 10 '13 at 06:58
  • 1
    What is your Entity set file extension? If it is dbml then it will work else not – Amit Dec 10 '13 at 07:00
  • unfortunately it is dbmx, any idea how to circumvent this obstacle ? – molu2008 Dec 10 '13 at 07:04
  • `InsertOnSubmit` is a Linq-to-SQL method and not in the Entity Framework.so plz check your file name it should me .dbml.but if u r not getting any error with add that means it's not a dbml file and u r working with entity framework. – Rahul Dec 10 '13 at 07:11
  • 1
    You can remove the whole line `m_model.UserExtendedDataSet.InsertOnSubmit(data);`. The context already tracks `User` and it is saved (updated, not inserted, as the method name suggests) when you call `SaveChanges`. – Gert Arnold Dec 10 '13 at 07:24

1 Answers1

2

What is your Entity set file extension? If it is dbml then it will work else not in case of dbmx

Reference

Community
  • 1
  • 1
Amit
  • 15,217
  • 8
  • 46
  • 68