gpt4 book ai didi

c# - WCF SQL 插入 GUID 转换错误

转载 作者:太空宇宙 更新时间:2023-11-03 22:10:34 25 4
gpt4 key购买 nike

我不确定该怎么做,

我想使用 WCF 为我的用户添加唯一标识符,当我向我的客户数据上下文添加 GUID 时,它会抛出此错误

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

有什么机会可以帮忙吗?

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();
}

public 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);
}

最佳答案

问题出在您的 Subscribe 方法中的这一行:

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

您将 GUID 类型的 clientID 传递给 Insert() 而您应该传递 ServiceFairy.client 类型的对象。

看起来您应该创建一个新的 client 对象并保存它:

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

如 TODO 所示,您还应该设置其他 client 属性。

关于c# - WCF SQL 插入 GUID 转换错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6785453/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com