我现在已经花了几个小时试图想出一种在WCF服务和客户端之间共享我的实体类的方法。问题是当我选择“在引用的程序集中重用类型”时,我的服务引用完全为空。我有两份服务合同:
public class ServiceUser : Service<User>, IServiceUser
{
public ServiceUser()
{
AtcContext context = new AtcContext();
Set = context.Users;
}
public virtual User Validate(string userName, string hashPassword)
{
UserValidator userValidator = new UserValidator();
userValidator.Validate(userName, hashPassword);
return userValidator.AuthenticatedUser;
}
}
和
public class ServiceEmployee : Service<Employee>, IServiceEmployee
{
public ServiceEmployee()
{
Context = new AtcContext();
Set = Context.Employees;
}
public Employee GetSingleBySequence(string sequence)
{
Employee entity = Set.Where(e => e.Sequence == sequence).FirstOrDefault();
if (entity == null)
{
throw new BdlFramework.Exceptions.BdlEntryNotFoundException();
}
return entity;
}
public Employee GetSingleByName(string FirstName, string LastName)
{
Employee entity = Set.Where(e => e.FirstName == FirstName && e.LastName == LastName).FirstOrDefault();
if (entity == null)
{
throw new BdlFramework.Exceptions.BdlEntryNotFoundException();
}
return entity;
}
public int GetNextSequence()
{
try
{
return Set.Where(e => SqlFunctions.IsNumeric(e.Sequence) > 0).Select(e => e.Sequence).Cast<int>().Max() + 1;
}
catch(Exception e)
{
Console.WriteLine(e);
}
return 1;
}
}
实体看起来有点像这样:
public class User : BaseKeyEntity
{
[Key, ForeignKey("Employee")]
[DataMember]
public new int Id
{
get
{
return this._Id;
}
set
{
if (this._Id != value)
{
this._Id = value;
this.OnPropertyChanged("Id");
}
}
}
private string _UserName = "";
[Required]
[StringLength(20)]
[Index("IX_User_UserName", 1, IsUnique = true)]
[DataMember]
public string UserName
{
get
{
return this._UserName;
}
set
{
if (this._UserName != value)
{
this._UserName = value;
this.OnPropertyChanged("UserName");
}
}
}
}
(实体代码的很大一部分被抑制)。
任何人都知道这里发生了什么?