2011-03-03 64 views
1

1類實體框架錯誤在asp.net

public partial class Profile : BaseEntity 
{ 
    #region Properties 
    /// <summary> 
    /// Gets or sets the Profile identifier 
    /// </summary> 
    public int ProfileId { get; set; } 

    /// <summary> 
    /// Gets or sets the FullName 
    /// </summary> 
    public string FullName { get; set; } 

    /// <summary> 
    /// Gets or sets the Gender 
    /// </summary> 
    public string Gender { get; set; } 

    /// <summary> 
    /// Gets or sets the DateofBirth 
    /// </summary> 
    public DateTime DateofBirth { get; set; } 

} 

2類

public partial interface IProfileService 
    { 

    /// <summary> 
    /// Gets an Profile by profile identifier 
    /// </summary> 
    /// <param name="profileid">profile identifier</param> 
    /// <returns>Profile</returns> 
    Profile GetProfileById(int profileid); 


    /// <summary> 
    /// Gets all Profiles 
    /// </summary> 
    /// <returns>Profile collection</returns> 
    List<Profile> GetAllProfiles(); 

    } 

3類

public partial class ProfileService : IProfileService 
{  
    /// <summary> 
    /// Gets a profile by profile identifier 
    /// </summary> 
    /// <param name="profileId">Profile identifier</param> 
    /// <returns>profile</returns> 
    public Profile GetProfileById(int profileid) 
    { 
     if (profileid == 0) 
      return null; 


     var query = from a in _context.Profilemasters 
        where a.ProfileId == profileid 
        select a; 
     var profile = query.SingleOrDefault(); 

     return profile; 
    } 
    } 

在返回輪廓I的第3類得到「無法隱式轉換'Data.Profilemaster'到'Library.Profile'的錯誤消息。 Whareas Data.Profilemaster是一個實體表和庫Library.Profile是類即ie。 1級。

而當我使用「MyContext.Profilemasters.AddObject(profile);」命令來插入數據我得到另一個錯誤消息,即。 「最佳重載方法匹配....」

請幫我。

我是Entrity Framework中的新成員。

任何人有觀念來解決這個

+0

你是如何讓你的個人資料類?你是如何創建映射的? – 2011-03-03 13:32:40

+0

我在項目的一個文件夾中使用所有這些類 – Joseph 2011-03-04 04:22:13

回答

1

嘗試像這樣.........

public ModelTest GetTest(int id) 
    { 
     ModelTest ob = new ModelTest(); 
     var a = from r in _QEntities.Tests 
       where r.id == id 
       select r; 
     foreach (var item in a) 
     { 
      ob.TestName = item.name; 
      ob.TotalMarks = item.totalmarks; 
     } 

     return ob; 
    }