EntityDataSource display in GridView
-
Thursday, February 21, 2013 7:56 PMI trust I can explain this enough to be understood. Two tables, table1 is AfricanRatings, table2 is AfricanRatingsAVG. Query
INSERT INTO AfricanRatingAVG
SELECT RecipeID, COUNT(*) AS Count, AVG(Rating) AS RatingAVG
FROM AfricanRatings
GROUP BY RecipeID
ORDER BY RecipeID
works fine. A EntityDataSource, with GridView, is set up and when a ItemTemplate Label with Text='<%# Eval("AfricanRatings.Count") %>'
is used, the .count is displayed correctly in the GridView.
An ItemTemplate Label with Text='<%# Eval("AfricanRatings.RatingAVG") %>' is placed into the GridView just below the .count eval.
Once the .RatingAVG eval is placed into the GridView, the following error message is given:
DataBinding: 'System.Data.Objects.DataClasses.EntityCollection`1[[TestDataBase.DAL.AfricanRating, TestDataBase,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' does not contain a property with the name 'RatingAVG'.
I'm looking right at the AfricanRatingAVG table and it has the fields RecipeID, Count, and RatingAVG for which the Count and
RatingAVG are rendered from AfricanRatings by the above query.
The eval for .count can be either AfricanRatings.Count or AfricanRatingsAVG.Count and works fine. An eval with AfricanRating (no s).Count
will not work and gives the error message DataBinding: 'TestDataBase.DAL.AfricanRecipe' does not contain a property with the name
'AfricanRating'.
Any help or explanation would be greatly appreciated.
Earl Davis
- Edited by EarlDavis1 Thursday, February 21, 2013 7:56 PM
- Moved by Kalman TothMicrosoft Community Contributor Thursday, February 21, 2013 11:18 PM Not T-SQL
All Replies
-
Thursday, February 21, 2013 8:06 PMPost your entity classes. Also, I think you're asking in the wrong forum and this may be moved to EF forum although as far as I know it's not very active.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
Thursday, February 21, 2013 8:44 PM
Naomi, thanks for the response. Sorry, but I'm not clear what you mean by entity classes. Do you mean the code in the AfricanRecipes.Model.Designer.cs, for example, the "public partial class AfricanRecipesEntities : ObjectContext" or a copy of the AfricanRecipesModel.edmx?
Earl Davis
-
Thursday, February 21, 2013 9:55 PMYes, I meant the cs files for your models. I use Code First, so that's why I don't use designers, but I guess this is where the model is and we can see what properties (columns) are defined.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
Thursday, February 21, 2013 10:45 PM
Naomi, I hope this is the part you need. This seems like a huge under taking for you and I sincerely appreciate your help:
public static AfricanRating CreateAfricanRating(global::System.Int32 ratingID, global::System.Int32 recipeID, global::System.Int32 rating, global::System.String comment)
{
AfricanRating africanRating = new AfricanRating();
africanRating.RatingID = ratingID;
africanRating.RecipeID = recipeID;
africanRating.Rating = rating;
africanRating.Comment = comment;
return africanRating;
}
#endregion
#region Primitive Properties
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 RatingID
{
get
{
return _RatingID;
}
set
{
if (_RatingID != value)
{
OnRatingIDChanging(value);
ReportPropertyChanging("RatingID");
_RatingID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RatingID");
OnRatingIDChanged();
}
}
}
private global::System.Int32 _RatingID;
partial void OnRatingIDChanging(global::System.Int32 value);
partial void OnRatingIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 RecipeID
{
get
{
return _RecipeID;
}
set
{
OnRecipeIDChanging(value);
ReportPropertyChanging("RecipeID");
_RecipeID = StructuralObject.SetValidValue(value);
ReportPropertyChanged("RecipeID");
OnRecipeIDChanged();
}
}
private global::System.Int32 _RecipeID;
partial void OnRecipeIDChanging(global::System.Int32 value);
partial void OnRecipeIDChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 Rating
{
get
{
return _Rating;
}
set
{
OnRatingChanging(value);
ReportPropertyChanging("Rating");
_Rating = StructuralObject.SetValidValue(value);
ReportPropertyChanged("Rating");
OnRatingChanged();
}
}
private global::System.Int32 _Rating;
partial void OnRatingChanging(global::System.Int32 value);
partial void OnRatingChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
[DataMemberAttribute()]
public global::System.String Comment
{
get
{
return _Comment;
}
set
{
OnCommentChanging(value);
ReportPropertyChanging("Comment");
_Comment = StructuralObject.SetValidValue(value, false);
ReportPropertyChanged("Comment");
OnCommentChanged();
}
}
private global::System.String _Comment;
partial void OnCommentChanging(global::System.String value);
partial void OnCommentChanged();
/// <summary>
/// No Metadata Documentation available.
/// </summary>
[EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
[DataMemberAttribute()]
public Nullable<global::System.Int32> IPAddress
{
get
{
return _IPAddress;
}
set
{
OnIPAddressChanging(value);
ReportPropertyChanging("IPAddress");
_IPAddress = StructuralObject.SetValidValue(value);
ReportPropertyChanged("IPAddress");
OnIPAddressChanged();
}
}
private Nullable<global::System.Int32> _IPAddress;
partial void OnIPAddressChanging(Nullable<global::System.Int32> value);
partial void OnIPAddressChanged();
Earl Davis
-
Thursday, February 21, 2013 11:55 PM
Is it the only file? Why there is AfrcianRating and you're referring to AfricanRatings?
Anyway, the error seems to tell you that no such property exist and in this file I only see these properties:
{
AfricanRating africanRating = new AfricanRating();
africanRating.RatingID = ratingID;
africanRating.RecipeID = recipeID;
africanRating.Rating = rating;
africanRating.Comment = comment;
return africanRating;
}For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
Friday, February 22, 2013 3:40 AM
Naomi, I am using MS Visual Studio and the Entity Model and all code is automatically generated. I also noticed the AfricanRating table name change by the Model. The actual table name is AfricanRatings but the Model shows it as AfricanRating - however, African Recipes, which is the main table to which AfricanDirections and AfricanRatings are both relational by all three tables having the key of recipeID, shows a navigation property to AfricanRatings - this seem odd to me but since it is auto-generated I assumed it was just the way the model works.
What is even more confusing to me is that when I do the Text='<%# Eval("AfricanRatings.Count") %>' the GridView will display the correct .count value for both AfricanRatings and AfricanRatingsAVG BUT will throw an error message if AfricanRating.Count is used.
The below AfricanDirection (name) given by the Model is really named AfricanDirections in the actual table. However, the Navigation Property is named AfricanDirections. If you aren't familiar with the EntityModel generated by Visual Studio, in the actual model diagram each table is given with a name and then at the bottom of the table model, the Navigation Properties are listed (basically stating which other tables the respective table is related.)
Interestingly enough, what the Model does on generation is to drop the "s" off any table ending with an "s", but retains the "s" when generating the Navigation Properties. Everything seems to work however, except for the initial problem I described above.
Hopefully the following are all the properties for the model:
public partial class AfricanRecipesEntities (this is the actual model name and the model has tables: AfricanRecipes, AfricanDirections, AfricanRatings, and AfricanRatingsAVG)
public partial class AfricanDirection
public static AfricanDirection
AfricanDirection africanDirection = new AfricanDirection();
africanDirection.DirectionsID = directionsID;
africanDirection.RecipeID = recipeID;
africanDirection.Name = name;
africanDirection.IngredientOne = ingredientOne;
africanDirection.IngredientTwo = ingredientTwo;
africanDirection.DirectionOne = directionOne;
return africanDirection;
public partial class AfricanRatingsAVG
public static AfricanRatingsAVG
AfricanRatingsAVG africanRatingsAVG = new AfricanRatingsAVG();
africanRatingsAVG.RecipeID = recipeID;
africanRatingsAVG.Count = count;
africanRatingsAVG.RatingAVG = ratingAVG;
return africanRatingsAVG;
public partial class AfricanRecipe
public static AfricanRecipe
AfricanRecipe africanRecipe = new AfricanRecipe();
africanRecipe.RecipeID = recipeID;
africanRecipe.Category = category;
africanRecipe.Name = name;
africanRecipe.Description = description;
return africanRecipe;
public partial class AfricanRating
public static AfricanRating
AfricanRating africanRating = new AfricanRating();
africanRating.RatingID = ratingID;
africanRating.RecipeID = recipeID;
africanRating.Rating = rating;
africanRating.Comment = comment;
return africanRating;
Earl Davis
- Edited by EarlDavis1 Friday, February 22, 2013 3:43 AM
-
Friday, February 22, 2013 4:25 PMI think we better wait for the answer of the expert in EF.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog -
Friday, February 22, 2013 6:55 PMNaomi, thank you very much for your time.
Earl Davis
-
Saturday, February 23, 2013 8:50 PM
Naomi, I was able to get the results I was after. I am not sure which of the following steps or if all the steps are necessary, but FYI the following is the answer:
1. I took all "s"es off the table names.
2. I made a relationship between the main table and the AfricanRatingsAVG table using recipeID as the key in both tables.
3. I maintained a relationship between the AfricanRatings table and the AfricanRatingsAVG table using "ratingsID" and "recipeID" to form the relationship.
I went into the code and changed all the incorrect code regarding table names and that did not work.
Thanks again for your help.
Earl Davis
- Proposed As Answer by Naomi NMicrosoft Community Contributor Sunday, February 24, 2013 3:33 AM
- Marked As Answer by Jack Zhai - MSFTMicrosoft Contingent Staff, Moderator Monday, February 25, 2013 1:40 AM

