WCF服务到SQL Server的数据错误 [英] WCF service to SQL server Data Error

查看:84
本文介绍了WCF服务到SQL Server的数据错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在编写一个WCF服务,该服务从SQL Server数据库中获取数据,并使用Linq to Entities在前端显示该数据.

以下是类接口:-

Hello All,

I am writing a WCF service that fetches data from SQL server database and shows it in front end using Linq to Entities.

Following is Class Interface:-

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace PIAService
{
    [ServiceContract]
    public interface IPIAService
    {
        [OperationContract]
        IQueryable<DataAccountDataModel> GetDetailsUsingPatientaccountNumber(string patientAccountNumber);
    }
}


以下是DataClass


Following is DataClass

public class DataAccountDataModel
  {
      [DataMember]
      public String PatientAccountNumber { get; set; }
      [DataMember]
      public String PatientName { get; set; }
      [DataMember]
      public String BARStatus_ORPH { get; set; }
      [DataMember]
      public String AdmitDate { get; set; }
}


以下是接口功能的实现


Following is Interface Function Implementtion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

using System.Data.Entity;
using StoreDB;

namespace PIAService
{
    [DataContract]
    public class PIAService : IPIAService 
    {

        public IQueryable <dataaccountdatamodel> GetDetailsUsingPatientaccountNumber(string patientAccountNumber)
        {
            PIADataModel piaData = new PIADataModel();
            
            IQueryable <dataaccountdatamodel> DAdetails = (from p in piaData.DataAccounts
                                                           where p.PatientAccountNumber == patientAccountNumber &&
                                                           p.Duplicate == false 
                                                           select p);

            return DAdetails;
         }
        
    }


通过编译该程序,我得到以下错误.请帮忙.


By compiling this program i am getting the following error. Kindly help.

Error	1	Cannot implicitly convert type 'System.Linq.IQueryable<storedb.dataaccount>' to 'System.Linq.IQueryable<piaservice.dataaccountdatamodel>'. An explicit conversion exists (are you missing a cast?)


在此先感谢.

Chowdary.


Thanks in Advance.

Chowdary.

推荐答案

如果您使用的是实体框架,则无需再次编写DTO,而可以使用您的实体类.
试试这个

在您的PIAService类中

If you are using entity framework means you no need to write DTO again, instead you can use your entity class.

try this

in your PIAService class

List <dataaccountdatamodel> DAdetails = (from p in piaData.DataAccounts
                                                           where p.PatientAccountNumber == patientAccountNumber &&
                                                           p.Duplicate == false
                                                           select new dataaccountdatamodel{ AAA = p.aaa,BBB=p.bbb}.tolist<dataaccountdatamodel>());</dataaccountdatamodel>



将此添加到您的界面IPIAService



add this in your interface IPIAService

[OperationContract]
List <dataaccountdatamodel> GetDetailsUsingPatientaccountNumber(string patientAccountNumber);


您缺少转换,请尝试以下操作
you missing casting, try following
IQueryable<dataaccountdatamodel> DAdetails = (from p in piaData.DataAccounts
                                                           where p.PatientAccountNumber == patientAccountNumber && p.Duplicate == false select p).ToList();


这篇关于WCF服务到SQL Server的数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆