Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
I am attempting to create a Repository/Specification pattern on my Entity Framework data model based on your example. However, I get an error when attempting to add the records. The error states The EntitySet name 'XXX' could not be found. It has the correct name, but cannot find it. It generates the error when the Add is reached:

C#
ProductManger testProduct = new ProductManger();
List<Product> newProductList = new List<Product>
Console.WriteLine("Adding New Product.......");

For (int i = 1; i <= 5; i++)
{
string productName = "Product Name";
Product prod = AddDefaultProduct(productName)
newProductList.Add(prod);
}


Which calls...

C#
public void Add(E entity)
{
    _ctx.AddObject(entity.GetType().Name, entity);
}


If I comment this out the program runs, I can write this list out to the screen, but cannot add it to the database.

Please advise as to how to correct the error that is being generated.
Posted
Updated 17-Dec-10 3:30am
v6

1 solution

You need to specify the list type also on the other side of the '='. It seems unnecessary because you already gave the type but when passing it as parameter this doesn't work. So change:
C#
List<product> newProductList = new List

to:
List<Product> newProductList = new List<Product>


Good luck!
   
Comments
aragiato 17-Dec-10 9:23am
   
I am already doing this.

List<Product> newProductList = new List<Product>

I can write this list out to the screen, but cannot add it to the database.

It is blowing up on the add. If I comment this line out the program runs.

newProductList.Add(prod);

Which calls...

public void Add(E entity)
{
_ctx.AddObject(entity.GetType().Name, entity);
}

It spits out the correct type in the error, but says it cannot find it.
E.F. Nijboer 17-Dec-10 12:52pm
   
Ah okay. In your initial question that wasn't visible.
Have a look at these links. I think those make it more clear, especially the first link ;-)
http://www.codeproject.com/KB/database/ImplRepositoryPatternEF.aspx
http://www.codeproject.com/KB/database/IntroEntityFramework3.aspx
http://www.codeproject.com/KB/architecture/LinqEntityFramework.aspx
http://www.code-magazine.com/article.aspx?quickid=0711051&page=1
http://msdn.microsoft.com/en-us/library/aa697427%28v=vs.80%29.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900