【发布时间】:2012-12-06 09:39:55
【问题描述】:
我为我的模型使用实体框架(edmx 文件),并且我正在使用 WCF 来访问我的模型。 当尝试返回实体数据模型(示例表对象)列表时,出现错误:
服务器没有提供有意义的回复;这可能是由于合同不匹配、会话过早关闭或内部服务器错误造成的。
这是我的 WCF 代码。 IService.cs:
[ServiceContract(CallbackContract = typeof(IPesananCallBack), SessionMode = SessionMode.Required)]
public interface IPelayanWebService
{
[OperationContract]
List<table> GetAllTables();
}
Service.cs:
public List<table> GetAllTables()
{
TableModel model = new TableModel();
return model.GetAllTables();
}
我在模型中的代码:
public List<table> GetAllTables()
{
using (restoicdbEntities ent = new restoicdbEntities())
{
return ent.table.ToList();
}
}
在我的客户端中,我只是调用了该函数,然后发生了错误。 我必须创建自己的数据合同吗?有没有办法从 edmx 生成数据合约?
更新: 这是从 Entity Framework 生成的代码:
[EdmEntityTypeAttribute(NamespaceName="restoicdbModel", Name="table")]
[Serializable]
[DataContractAttribute(IsReference=true)]
public partial class table: EntityObject
{
[EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
[DataMemberAttribute()]
public global::System.Int32 ID_TABLE
{
get
{
return _ID_TABLE;
}
set
{
if (_ID_TABLE != value)
{
OnID_TABLEChanging(value);
ReportPropertyChanging("ID_TABLE");
ID_TABLE = StructuralObject.SetValidValue(value);
ReportPropertyChanged("ID_TABLE");
OnID_TABLEChanged();
}
}
}
private global::System.Int32 ID_TABLE;
partial void OnID_TABLEChanging(global::System.Int32 value);
partial void OnID_TABLEChanged();
}
【问题讨论】:
-
您使用的是哪个版本的实体框架?您的实体是 POCO 吗?
-
我使用的是 2.0 版本,我的实体是从 edmx 生成的。
-
其实我怎么看版本?我从 xml 中查看 ..
-
您的实体是否派生自EntityObject?
标签: c# .net wcf entity-framework edmx