locked
EF 3.5 Desginer generate code problem RRS feed

  • Question

  • hi freinds.

    i' using visual studio 2010 with .net 3.5

    i have an EF model. when i build project there are some errors like

    Cannot implicitly convert type 'Model.OrganizationCategory' to 'OrganizationCategory'
    
    'OrganizationCategory' does not contain a definition for 'Organizations' and no extension method 'Organizations' accepting a first argument of type 'OrganizationCategory' could be found (are you missing a using directive or an assembly reference?)
    (while in my Model i can see the navigation property Organizations)

    but they are both of same type (in below code u can see it )!!!!!

    i found problem origin in Model Designer, when i see errors I move positions of some entities in designer and press F6, then Errors

    disappears. So again I move some entities positions and then press F6 then errors appears again!!!!!

     

    note that i have one mode with Model namspace and Entities container.

    here is my code:

    note that I've marked errors below of each line

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Model;
    
    public partial class OrganizationsForm : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
        Class1.removeEditDeleteButton(this, GridView1, (Page.Master as SiteMaster).Menu);
        MessgaeControl1.Text = "";
      }
    
      void Page_LoadComplete(object sender, EventArgs e)
      {
        FillGrid();
      }
    
      //Search Parameters
      private string organizationName = "";
      private Country selectedCountry;
      private Province selectedProvince;
      private City selectedCity;
      private Region selectedRegion;
      private OrganizationCategory selectedOrganizationCategory;
    
      
      private void FillGrid()
      {
        using (Entities ctx = new Entities())
        {
          organizationName = TextBox1.Text;
          if (OrganizationCategoryTree1.SelectedValue != "")
          {
            int ID = int.Parse(OrganizationCategoryTree1.SelectedValue);
    
            selectedOrganizationCategory = ctx.OrganizationCategories.First(c => c.ID == ID);
            //Error	2	Cannot implicitly convert type 'Model.OrganizationCategory' to 'OrganizationCategory'
          }
          else
          {
            selectedOrganizationCategory = ctx.OrganizationCategories.First(c => c.Name == "سازمان");
            //Error	3	Cannot implicitly convert type 'Model.OrganizationCategory' to 'OrganizationCategory'
    
          }
          if (CountryProvince1.SelectedCountryID != "")
          {
            int countryID = int.Parse(CountryProvince1.SelectedCountryID);
            selectedCountry = ctx.Countries.First(c => c.CountryId == countryID);
          }
          if (CountryProvince1.SelectedProvinceID != "")
          {
            int provinceID = int.Parse(CountryProvince1.SelectedProvinceID);
            selectedProvince = ctx.Provinces.First(c => c.ProvinceId == provinceID);
          }
          if (CountryProvince1.SelectedCityID != "")
          {
            int cityID = int.Parse(CountryProvince1.SelectedCityID);
            selectedCity = ctx.Cities.First(c => c.CityId == cityID);
          }
          if (CountryProvince1.SelectedRegionID != "")
          {
            int regionID = int.Parse(CountryProvince1.SelectedRegionID);
            selectedRegion = ctx.Regions.First(c => c.ID == regionID);
          }
    
          GridView1.DataSource = AllFactsInCategory(selectedOrganizationCategory, new List<Organization>());
          GridView1.DataBind();
        }
      }
    
      List<Organization> AllFactsInCategory(OrganizationCategory OrganizationCategory, List<Organization> lst)
      {
        using (Entities ctx = new Entities())
        {
          OrganizationCategory.Organizations.Load();
          //Error	4	'OrganizationCategory' does not contain a definition for 'Organizations' and no extension method 'Organizations' accepting a first argument of type 'OrganizationCategory' could be found (are you missing a using directive or an assembly reference?)
          OrganizationCategory.Children.Load();
          //Error	5	'OrganizationCategory' does not contain a definition for 'Children' and no extension method 'Organizations' accepting a first argument of type 'OrganizationCategory' could be found (are you missing a using directive or an assembly reference?)
          foreach (var organization in OrganizationCategory.Organizations)
            //Error	6	'OrganizationCategory' does not contain a definition for 'Organizations' and no extension method 'Organizations' accepting a first argument of type 'OrganizationCategory' could be found (are you missing a using directive or an assembly reference?)
            if (OrganizationIsInCountryProvince(organization))
              lst.Add(organization);
          foreach (var item in OrganizationCategory.Children)
            //Error	7	'OrganizationCategory' does not contain a definition for 'Children' and no extension method 'Organizations' accepting a first argument of type 'OrganizationCategory' could be found (are you missing a using directive or an assembly reference?)
            AllFactsInCategory(item, lst);
          return lst;
        }
      }
    

    i need some one, i give him my project source, to find the problem.

    Monday, December 27, 2010 8:54 AM

Answers

  • Hi.

    Today finally I found the problem.

    I have had a user control with name OrganizationCategory, I deleted it. But VS keeped it temp folder. And this class was problem origin.

    Today I change my OrganizationCategory enity name to  OrganizationCategory1 and I see that the OrganizationCategory class name still exist in intellicensce pop up menu but I went to its definition and a class from temp folder (my user control class) opened and this is how I find problem.

    • Marked as answer by Zarei Ramin Tuesday, December 28, 2010 5:00 PM
    Tuesday, December 28, 2010 5:00 PM

All replies

  • it's 3 days i can't find the problem. please some one help me.
    Monday, December 27, 2010 4:10 PM
  • Hi.

    Today finally I found the problem.

    I have had a user control with name OrganizationCategory, I deleted it. But VS keeped it temp folder. And this class was problem origin.

    Today I change my OrganizationCategory enity name to  OrganizationCategory1 and I see that the OrganizationCategory class name still exist in intellicensce pop up menu but I went to its definition and a class from temp folder (my user control class) opened and this is how I find problem.

    • Marked as answer by Zarei Ramin Tuesday, December 28, 2010 5:00 PM
    Tuesday, December 28, 2010 5:00 PM