错误2062:没有为EntityContainer中的EntitySet和AssociationSet实例指定映射

时间:2015-05-12 16:28:54

标签: c# connection

我只是......

public TEntity GetSingle(ISpecification<TEntity> Specification)
    {
        //return this._Context.CreateDbSet<TEntity>()
        //    .SingleOrDefault<TEntity>(Specification.SatisfiedBy());
        if (Specification == null)
        {
            throw new ArgumentNullException("Specification");
        }
        IEnumerable<TEntity> source = this._Context.CreateDbSet<TEntity>().Where(Specification.SatisfiedBy()).AsEnumerable<TEntity>();
        if (source.Count<TEntity>() > 0)
        {
            return source.First<TEntity>();
        }
        return default(TEntity);
    }

...在尝试执行此操作时出现错误._Context.CreateDbSet()

错误标记为绿色,消息类似于:

Exception of type 'System.Data.Entity.Core.MappingException' at mscorlib.dll but it was not caught by user code.
Additional Information: Schema specified is not valid. Errors: 
Models.Company.CompanyModel.msl(3,4) : error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer iOfferEntities.

我在Web.config和App.config上有以下连接字符串,如...

<add name="iOfferEntities" connectionString="metadata=res://*/Models.Company.CompanyModel.csdl|res://*/Models.Company.CompanyModel.ssdl|res://*/Models.Company.CompanyModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=192.168.1.31;initial catalog=mto3;persist security info=True;user id=myuserid;password=mypassword;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

我与同一服务器中的另一个数据库建立连接,我可以正常工作。

有什么想法吗?

谢谢!!!

1 个答案:

答案 0 :(得分:1)

好吧,我创建了一个新模型并摆脱了有问题的模型。到目前为止问题已解决无论如何,谢谢大家。