Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Lambda连接错误_C#_.net_Linq_Lambda - Fatal编程技术网

C# Lambda连接错误

C# Lambda连接错误,c#,.net,linq,lambda,C#,.net,Linq,Lambda,我在连接两个表时遇到问题,并继续收到“无法从用法推断。请尝试显式指定类型参数。” “方法的类型参数出现错误2。” 'System.Linq.Enumerable.Join(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Func,System.Func, 无法从中推断System.Func“” 用法。请尝试显式指定类型参数。C:\Pro Asp.net Mvc 5\第13

我在连接两个表时遇到问题,并继续收到“无法从用法推断。请尝试显式指定类型参数。”

“方法的类型参数出现错误2。” 'System.Linq.Enumerable.Join(System.Collections.Generic.IEnumerable, System.Collections.Generic.IEnumerable, System.Func,System.Func, 无法从中推断System.Func“” 用法。请尝试显式指定类型参数。C:\Pro Asp.net Mvc 5\第13章\1\体育商店- 复制\sportstore.WebUI\Controllers\DocProductController.cs 29 17 sportstore.WebUI“

有人能帮我吗

public class DocProductController : Controller
{
    private IDocProductRepository repository;
    private IDocMainRepository repositoryMain;

    public DocProductController(IDocProductRepository docProductRepository, IDocMainRepository docMainRepository)
    {
        this.repository = docProductRepository;
        this.repositoryMain = docMainRepository;
    }


    public ViewResult List()
    {
        DocProductListView model = new DocProductListView
        {
            DocProduct = repository.DocProduct
            .Join(repositoryMain.DocMain,
            docProduct => docProduct,
            docMain => docMain.Doc_Id,
            (docProduct, docMain) => new { a = docMain.Doc_Id, b = docProduct.Doc_Id })
           //.OrderByDescending(n => n.DocMain)
        };

        return View(model);
    }
}



public partial class DocMain
{
    public int Doc_Id { get; set; }
    public Nullable<int> Category_Id { get; set; }
    public string Doc_Title { get; set; }
    public Nullable<int> Doc_Order { get; set; }
    public Nullable<byte> Doc_IsAudit { get; set; }
    public Nullable<int> Doc_Clicks { get; set; }
    public string Doc_TitleColor { get; set; }
    public string Doc_Author { get; set; }
    public Nullable<int> User_Id { get; set; }
    public string Doc_Source { get; set; }
    public string Doc_Thumb { get; set; }
    public Nullable<System.DateTime> Doc_DisplayTime { get; set; }
    public Nullable<System.DateTime> Doc_ReleaseTime { get; set; }
    public Nullable<System.DateTime> Doc_UpdateTime { get; set; }
    public string Doc_SEO_Title { get; set; }
    public string Doc_SEO_Description { get; set; }
    public string Doc_SEO_Keywords { get; set; }
    public string Doc_RedirectUrl { get; set; }
    public Nullable<byte> Doc_GenerateHTML { get; set; }
    public string Doc_HTMLCatagory { get; set; }
}



public partial class DocProduct
{
    public int Doc_Id { get; set; }
    public Nullable<int> Category_Id { get; set; }
    public string DocProduct_Content { get; set; }
}
公共类DocProductController:控制器
{
私有知识库;
私营企业在储蓄性回购中的地位;
公共DocProductController(IDocProductRepository docProductRepository、IDocMainRepository docMainRepository)
{
this.repository=docProductRepository;
this.repositoryMain=docmain存储库;
}
公共视图结果列表()
{
DocProductListView模型=新的DocProductListView
{
DocProduct=repository.DocProduct
.Join(repositoryMain.DocMain,
docProduct=>docProduct,
docMain=>docMain.Doc\u Id,
(docProduct,docMain)=>new{a=docMain.Doc\u Id,b=docProduct.Doc\u Id})
//.OrderByDescending(n=>n.DocMain)
};
返回视图(模型);
}
}
公共部分类DocMain
{
public int Doc_Id{get;set;}
公共可空类别_Id{get;set;}
公共字符串Doc_Title{get;set;}
公共可为空的Doc_Order{get;set;}
公共可为空的Doc_IsAudit{get;set;}
公共可空文档_单击{get;set;}
公共字符串Doc_TitleColor{get;set;}
公共字符串Doc_Author{get;set;}
公共可为空的用户\u Id{get;set;}
公共字符串Doc_源{get;set;}
公共字符串Doc_Thumb{get;set;}
公共可为空的Doc_DisplayTime{get;set;}
公共可为空的Doc_ReleaseTime{get;set;}
公共可为空的Doc_UpdateTime{get;set;}
公共字符串Doc_SEO_Title{get;set;}
公共字符串Doc\u SEO\u Description{get;set;}
公共字符串Doc\u SEO\u关键字{get;set;}
公共字符串Doc_重定向URL{get;set;}
公共可为空的Doc_GenerateHTML{get;set;}
公共字符串Doc_HTMLCatagory{get;set;}
}
公共部分类乘积
{
public int Doc_Id{get;set;}
公共可空类别_Id{get;set;}
公共字符串DocProduct_内容{get;set;}
}
这一行应该改为

docProduct => docProduct.Doc_Id
因为这是你加入的关键

通常,该消息所指的是,当您调用泛型方法时,它会尝试推断类型参数。e、 g

public void MyMethod<T>(T input)
因为0是int,编译器可以计算出
T
必须是int

但如果你有:

public void MyMethod<T>(T input1, T input2)
现在,您将看到一条与您收到的错误消息类似的错误消息,因为没有可供推断的合理类型
T
——无论是字符串还是int,都会有一个参数错误


因此,通常情况下,该消息表示某个参数的类型错误。有时,它也可能出现在类型正确的情况下,但存在一些歧义,这导致编译器无法计算泛型类型。如果不确定参数的类型是否错误,可以尝试显式指定它们,如第一个调用
MyMethod
的示例。至少,它可能会为您提供一个有关类型不匹配发生位置的更多信息错误。

@user3339775您能解释一下为什么要加入吗?@user3339775是的,但您选择的是DocProduct。因此,您想要包含的任何属性都必须是DocProduct上的属性。我不确定您是否更熟悉SQL,但这就像您尝试将联接的结果插入到表中一样。插入的联接中的字段必须是目标表中的字段。同样,您要在此处选择的属性必须是目标对象上的属性。@user3339775老实说,我将为此创建一个新问题,因为这实际上是一个单独的问题,最好是有问题和答案,而不仅仅是评论。@user3339775如果你真的提出了一个新问题,你可能应该明确说明你到底做了什么和不理解什么,以及你的知识/经验水平是什么,因为我觉得很难判断。
MyMethod<int>(0);
MyMethod(0);
public void MyMethod<T>(T input1, T input2)
MyMethod(0, "Hello");