开发者

Entity not resolved in code first DataService with Entity Framework 4.1

I'm making a DataService with Entity Framework 4.1 using Code First POCO objects. I can access the data fine when I create an instance of MyEntityContext and access it directly, however when I try and开发者_如何学JAVA access the DataService over HTTP it breaks with the following error:

System.ArgumentException: The given name 'Department' was not found in the entity sets.

I've tried all sorts of things but keep coming back to the same problem. Not sure what could be wrong.

Department is the only Entity I am mapping currently. It is defined as follows:

[Table("tb_department")]
public class Department
{        
    [Key]
    [Column("department_no", TypeName = "nvarchar")]
    public string ID { get; set; }

    [Column("department_name", TypeName = "nvarchar")]
    public string Name { get; set; }        
}

My data context looks like this:

public class MyEntityContext : DbContext
{
    public MyEntityContext(string connStr)
        : base(connStr)
    {
    }

    public MyEntityContext()
    {
    }

    public DbSet<Department> Departments { get; set; }
}

And my service looks like this:

[ServiceBehavior(IncludeExceptionDetailInFaults = true)]
public class MyDataService : DataService<MyEntityContext>
{
    public static void InitializeService(DataServiceConfiguration config)
    {
        config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        config.UseVerboseErrors = true;
        config.SetEntitySetAccessRule("Department", EntitySetRights.AllRead);            
    }

    protected override MyEntityContext CreateDataSource()
    {
        MyEntityContext ctx = new MyEntityContext(
            Utility.GenerateConnStr
        );

        return ctx;
    }
}


Well it says "Department" was not found in the entity sets and your entity set name is "Departments" so try pluralizing the call.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜