没有映射从对象类型WebMatrix.Data.DynamicRecord存在一个已知的托管提供原生型 [英] No mapping exists from object type WebMatrix.Data.DynamicRecord to a known managed provider native type

查看:264
本文介绍了没有映射从对象类型WebMatrix.Data.DynamicRecord存在一个已知的托管提供原生型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑与我的SQL服务器返回错误 - 这将是导致此

I am very confused with the error my SQL server is returning - what would be causing this?

我运行的C#代码是:

List<CalendarEvent> events = new List<CalendarEvent>();
        var db = Database.Open("myDatabase");
        string username = HttpContext.Current.Request.Cookies.Get("username").Value;
        var listOfGroups = db.Query("SELECT GroupID FROM Membership WHERE UserID = (SELECT UserID from Users WHERE Username = @0 )",  username);

        foreach(var groupID in listOfGroups)
            {
                var result = db.Query(
                    @"SELECT e.event_id, e.title, e.description, e.event_start, e.event_end, e.group_id, e.recurring
                    FROM   event e
                    JOIN   Membership m ON m.GroupID = e.group_id
                    WHERE  e.recurring = 0
                    AND    m.GroupID = @0
                    AND    e.event_start >= @1
                    AND    e.event_end <= @2
                    UNION ALL
                    SELECT e.event_id, e.title, e.description, DATEADD(week, w.weeks, e.event_start), DATEADD(week, w.weeks, e.event_end), e.group_id, e.recurring
                    FROM   event e
                JOIN   Membership m ON m.GroupID = e.group_id
                CROSS JOIN 
                    ( SELECT  row_number() OVER (ORDER BY Object_ID) AS weeks
                    FROM SYS.OBJECTS
                    ) AS w
                    WHERE  e.recurring = 1
                    AND    m.GroupID = $3
                    AND    e.event_start >= @4
                    AND    e.event_end <= @5", groupID, start, end, groupID, start, end
                );
                foreach(var record in result)
                    {
                            CalendarEvent cevent = new CalendarEvent();
                            cevent.id = record.event_id;
                            cevent.title = record.title;
                            cevent.description = record.description;
                            cevent.start = record.event_start;
                            cevent.end = record.event_end;
                            cevent.recurring = record.recurring;
                            events.Add(cevent);
                    }
            }
        return events;
}

和错误:

异常详细信息:System.ArgumentException:从
对象类型WebMatrix.Data.DynamicRecord不存在任何映射到一个已知的托管提供
机类型

Exception Details: System.ArgumentException: No mapping exists from object type WebMatrix.Data.DynamicRecord to a known managed provider native type.

什么可能会造成这一点,我怎么能解决这个问题?

What could be causing this and how can I fix it ?

我希望做的是回到那里经常性= 0的所有事件,并在经常性= 1我要为他们一周要返回的所有事件和52周一次。

What I wish to do is return all events where recurring = 0, and any events where recurring =1 I want to be returned for their week and the 52 weeks thereafter.

推荐答案

看起来像你的问题是与你的 GROUPID 输入参数。

Looks like your issue is with your groupID input parameter.

var listOfGroups = db.Query("SELECT GroupID FROM Membership WHERE UserID = (SELECT UserID from Users WHERE Username = @0 )",  username);

listOfGroups 是回来作为一个集合的 WebMatrix.Data.DynamicRecord 的对象。你似乎只想在 INT 价值,当你 GROUPID 的foreach(VAR 。GROUPID在listOfGroups)语句

Your listOfGroups is coming back as a collection of the WebMatrix.Data.DynamicRecord objects. You seem to want just the int value, as you get groupID in the foreach(var groupID in listOfGroups) statement.

尝试,而不是替换最后一行:

Try instead replacing the last line:

AND    e.event_end <= @5", groupID, start, end, groupID, start, end

AND    e.event_end <= @5", (int)groupID.GroupID, start, end, (int)groupID.GroupID, start, end

这应该拉从每个动态查询结果的第一(唯一的)列中的值,该值是,你是后整型组ID。



编辑:的DynamicRecord查询结果的修正值调用语法

This should pull the value from the first (and only) column of each dynamic query result, that value being the int group ID that you are after.

Corrected value call syntax of DynamicRecord query result.

这篇关于没有映射从对象类型WebMatrix.Data.DynamicRecord存在一个已知的托管提供原生型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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