开发者

WCF SQL insert GUID conversion error

开发者 https://www.devze.com 2023-03-22 07:39 出处:网络
I am unsure how to go about this, I want to add unique identifiers for my users using WCF and when I go to add a GUID to my clients datacontext it throws this error

I am unsure how to go about this,

I want to add unique identifiers for my users using WCF and when I go to add a GUID to my clients datacontext it throws this error

Error 2

Argument 1: cannot convert from 'System.Guid' to 'ServiceFairy.client' C:\Users\John\Documents\Visual Studio 2010\Projects\PremLeague\ServiceFairy\Service1.svc.cs

Any chance you can help?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
using System.Diagnostics;

namespace ServiceFairy
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class     name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
    public List<match> GetAllMatches()
    {
        matchtableDataContext context = new matchtableDataContext();
        var matches = from m in context.matches orderby m.Date select m;
        return matches.Take(100).ToList();
    }

    pu开发者_运维百科blic List<premtable> GetTable()
    {
        premContext context = new premContext();
        var table = from user in context.premtables orderby user.ID select   user;
        return table.Take(100).ToList();
    }

    public Dictionary<Guid, Uri> _clientUris = new Dictionary<Guid, Uri>();

    public void Subscribe(Guid clientID, string uri)
    {
        ClientsDBDataContext context = new ClientsDBDataContext();
        context.clients.Insert(clientID);           
    }       


The problem is in your Subscribe method at this line:

context.clients.Insert(clientID);   // error: clientID is the wrong type

You're passing clientID of type GUID to Insert() when instead you should be passing an object of type ServiceFairy.client.

It looks like you should be creating a new client object and saving that:

var client = new ServiceFairy.client() { ClientID = clientID };  // TODO: set other properties
context.clients.Insert(client);

As the TODO indicates, you should be setting other client properties too.


The error is as follows:

Error 2
Argument 1: cannot convert from 'System.Guid' to 'ServiceFairy.client' C:\Users\John\Documents\Visual Studio 2010\Projects\PremLeague\ServiceFairy\Service1.svc.cs 36 44 ServiceFairy

Reading this, we have:

  1. There is a problem with Argument 1. Checking the code at the line described, we can see that the first argument is 'clientId'.
  2. The 'clientId' object is of type 'System.Guid'.
  3. The first object needs to be of type 'ServiceFairy.client'.
  4. The system is unable to magically convert a 'System.Guid' to a 'ServiceFairy.client'.

The solution, therefore, is to figure out yourself how to get a 'ServiceFairy.client' object instead.

0

精彩评论

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

关注公众号