首页 > 移动平台 > 详细

Entity SQL rules for Wrapped and Unwrapped Results

时间:2014-01-15 23:57:49      阅读:511      评论:0      收藏:0      [点我收藏+]

Here are some rules to remember for Entity SQL queries:

1.Use SELECT VALUE when projecting more than one type;

2.When querying with SELECT,the ObjectQuery type must be a DbDataRecord ;

3.You can use SELECT VALUE when projecting a single value or entity;

4.When querying with SELECT VALUE,the ObjectQuery type must be the same type as the value being returned.

 

用 Entity SQL 查询“包装”和“未包装” 结果的规则:

下面是几条用Entity SQL 查询需要记住的规则:

1、当投射的类型超过一个时,用 select value ;

2、当用 select 查询时,ObjectQuery 结果集类型必须为DbDataRecord类型;

3、当查询单个值或单个实体的时候,推荐使用 select value 查询;

4、当用 select value 进行查询时,ObjectQuery 类型必须和返回值类型保持一致;

 

Examples:

1、Wrapped Contact needs to be cast:

bubuko.com,布布扣
private static void WrappedContactInEntitySql()
        {
            using (var context = new PEF())
            {
                var queryString =
                    "select c from PEF.Contacts as c where c.FirstName =‘Robert‘ ";

                var contacts = context.CreateQuery<DbDataRecord>(queryString);

                foreach (DbDataRecord c in contacts)
                {
                    var contact = (Contact)c[0];

                    Console.WriteLine("{0} {1} {2}",
                        contact.Title.Trim(),
                        contact.FirstName.Trim(),
                        contact.LastName.Trim());
                }

            }

            Console.WriteLine("Press Enter...");
            Console.ReadLine();

        }
bubuko.com,布布扣

2、Unwrapped Contact does not need to be cast:

bubuko.com,布布扣
private static void UnwrappedContactInEntitySql()
        {
            using (var context = new PEF())
            {
                var queryString =
                    "select value c from PEF.Contacts as c where c.FirstName = ‘Robert‘ ";

                var contacts = new ObjectQuery<Contact>(queryString, context);

                foreach (var contact in contacts)
                {
                    Console.WriteLine("{0} {1} {2}",
                        contact.Title.Trim(),
                        contact.FirstName.Trim(),
                        contact.LastName.Trim());
                }

            }

            Console.WriteLine("Press Enter...");
            Console.ReadLine();

        }
bubuko.com,布布扣

Entity SQL rules for Wrapped and Unwrapped Results

原文:http://www.cnblogs.com/ARMdong/p/3516001.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!