Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
.net core 无法检索字符串datamember的值_.net Core_Orm_Dapper - Fatal编程技术网

.net core 无法检索字符串datamember的值

.net core 无法检索字符串datamember的值,.net-core,orm,dapper,.net Core,Orm,Dapper,目标: 从datamember列Asdf和Zxcv的sql代码中检索值 问题: 我无法检索datamember列Asdf和Zxcv的值。 我无法找到错误,我丢失了代码的哪一部分 谢谢大家! var data = new Dictionary<Guid, Child>(); var queryee2 = @" SELECT CONVERT(

目标:
从datamember列Asdf和Zxcv的sql代码中检索值

问题:
我无法检索datamember列Asdf和Zxcv的值。
我无法找到错误,我丢失了代码的哪一部分

谢谢大家!

        var data = new Dictionary<Guid, Child>();

        var queryee2 = @"
                        SELECT
                            CONVERT(uniqueidentifier, 'c029f8be-29dc-41c1-8b38-737b4cc5a4df') AS ChildId,
                            1 AS SectionId,
                            1 as SchoolClassId,
                            1 as SchoolId,
                            'Daniel Dennett' AS Name, 
                            'aa' as Asdf,
                            'bb' as Zxcv,
                            1 as DropByContactId,
                            'f' as Firstname,
                            'f' as Lastname,
                            1 as ContactId

                        UNION ALL 

                        SELECT
                            CONVERT(uniqueidentifier, 'c029f8be-29dc-41c1-8b38-737b4cc5a4df') AS ChildId,
                            1 AS SectionId,
                            1 as SchoolClassId,
                            1 as SchoolId,
                            'Daniel Dennett' AS Name,
                            'aa' as Asdf,
                            'bb' as Zxcv,
                            0 as DropByContactId,
                            'f' as Firstname,
                            'f' as Lastname,
                            3 as ContactId
                        ";

        var ddfeedf = _db.Query<Child, Contact, Child>(queryee2, (child, contact) =>
        {
            //person
            Child personEntity;
            //trip
            if (!data.TryGetValue(child.ChildId, out personEntity))
            {
                data.Add(child.ChildId, personEntity = child);
            }
     
            if (personEntity.Contacts == null)
            {
                personEntity.Contacts = new List<Contact>();
            }

            if (contact != null)
            {
                if (!personEntity.Contacts.Any(x => x.ContactId == contact.ContactId))
                {
                    personEntity.Contacts.Add(contact);
                }
            }
            
            return personEntity;
        },
        splitOn: "ChildId,SchoolId").Distinct();



    public class Child
    {
        public Guid ChildId { get; set; }
        public int SectionId { get; set; }
        public int SchoolClassId { get; set; }
        public int SchoolId { get; set; }
        public string Name { get; set; }
        public string Asdf { get; set; }
        public string Zxcv { get; set; }
        public ICollection<Contact> Contacts { get; set; }
    }


    public class Contact
    {
        public int DropByContactId { get; set; }
        public string Firstname { get; set; }
        public string Lastname { get; set; }
        public int ContactId { get; set; }
    }
var data=newdictionary();
变量queryee2=@”
选择
将(唯一标识符“c029f8be-29dc-41c1-8b38-737b4cc5a4df”)转换为儿童ID,
1作为SectionId,
1作为学校的学生,
作为一名学生,
“Daniel Dennett”作为名字,
“aa”作为Asdf,
“bb”作为Zxcv,
1作为DropByContactId,
“f”作为名字,
“f”作为姓氏,
1作为联系人ID
联合所有
选择
将(唯一标识符“c029f8be-29dc-41c1-8b38-737b4cc5a4df”)转换为儿童ID,
1作为SectionId,
1作为学校的学生,
作为一名学生,
“Daniel Dennett”作为名字,
“aa”作为Asdf,
“bb”作为Zxcv,
0作为DropByContactId,
“f”作为名字,
“f”作为姓氏,
3作为联系人ID
";
var ddfeedf=_db.Query(queryee2,(子对象,联系人)=>
{
//人
儿童人格;
//绊倒
if(!data.TryGetValue(child.ChildId,out personEntity))
{
data.Add(child.ChildId,personEntity=child);
}
if(personEntity.Contacts==null)
{
personEntity.Contacts=新列表();
}
如果(联系人!=null)
{
如果(!personEntity.Contacts.Any(x=>x.ContactId==contact.ContactId))
{
personEntity.Contacts.Add(contact);
}
}
回归人格;
},
splitOn:“ChildId,SchoolId”).Distinct();
公营儿童
{
公共Guid ChildId{get;set;}
public int SectionId{get;set;}
public int SchoolClassId{get;set;}
公共int SchoolId{get;set;}
公共字符串名称{get;set;}
公共字符串Asdf{get;set;}
公共字符串Zxcv{get;set;}
公共ICollection联系人{get;set;}
}
公共类联系人
{
public int DropByContactId{get;set;}
公共字符串名{get;set;}
公共字符串Lastname{get;set;}
public int ContactId{get;set;}
}

Asdf
Zxcv
属于
Child
,但是您可以在这些列之前使用
SchoolId
拆分生成的行。您应该像这样更改
splitOn
列:

var-ddfeedf=\u db.Query(queryee2,(孩子,联系人)=>
{
//人
儿童人格;
//绊倒
if(!data.TryGetValue(child.ChildId,out personEntity))
{
data.Add(child.ChildId,personEntity=child);
}
if(personEntity.Contacts==null)
{
personEntity.Contacts=新列表();
}
如果(联系人!=null)
{
如果(!personEntity.Contacts.Any(x=>x.ContactId==contact.ContactId))
{
personEntity.Contacts.Add(contact);
}
}
回归人格;
},
splitOn:“ChildId,DropByContactId”).Distinct();
splitOn
-参数的用途如下:
连接的数据作为行和列的结果集提供。Dapper不知道您的数据模型,它只能映射到您定义的列名或映射。当需要映射到多个类的对象时,需要告诉Dapper如何将结果集拆分为指定的各个类。在您的示例中,您告诉Dapper“我的结果集包含<代码>子项<代码>和<代码>联系人<代码>”,但Dapper需要关于如何分割数据的提示。因此,您告诉它“ChildId”和“DropContactId”是分解结果集的列。然后Dapper将尝试将第一部分映射到
子项
,第二部分映射到
联系人
。请注意,“DropContactId”就足够了,因为第一个resultset部分是隐含的。另外请注意,
splitOn
是不必要的,如果所有拆分列都被称为“Id”,那么Dapper将自动执行此操作。

我还有一个问题。使用“splitOn”的目的是什么?