1

I learned some basic stuff on EF 4.0 and recently upgraded to EF 6.0. I can't seem to get a simple insert working. Has the "ent.AddtoImage()" been deprecated in version 6.0? I searched around but cannot find an answer.

using (evEntities ent = new evEntities())
{
Image insertImg = new Image();                                        

insertImg.TypeID = "a";
ent.AddtoImage(insertImg);
ent.SaveChanges();
}

I get a red squiggly line under AddtoImage ???

Edit: here is an image -

enter image description here

3 Answers 3

1

Assuming that Image is an entity generated by EF you can use

ent.Images.Add(insertImg);

in EF6, then the rest of your code.

Sign up to request clarification or add additional context in comments.

Comments

1

Yeah.

beacause evEntities is valid only in the scope of the using statement, which is the next block.

As you miss {} - that next blcock is the next statement, which is

Image insertImg = new Image ();

Right after that line, evEntities is disposed and the variable invalid.

Wrap the whole lines after using into curly braces to make them one block.

using (evEntities ent = new evEntities()) {
    ....rest of your code
}

3 Comments

sorry, I left out the braces. I actually have a lot of other code and was trying to simplify. But yeah, I have the braces/scope in my code. So AddToImage(insertImg) should work?
No idea, my crystal ball is broken. I have no idea about where this method comes from as you clearly do not love giving any relevant code. I find no reference to an AddTOImage method even in EF 4.... or on the whole internet.
Late and tired. Yes, you're right that I should have posted better. Thank you ... It's a usage of "Addto" which doesn't seem to be supported with EF 6. Here's the ref: blogs.msdn.com/b/wriju/archive/2008/08/21/… --- the Insert example uses AddtoEmp
0

Try this instead

evEntities.Entry<Image>(ent).State = EntityState.Added;
ent.SaveChanges();

or

evEntities.Set<Image>().Add(ent);
ent.SaveChanges();

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.