“对象"不包含动态定义 [英] 'object' does not contain a definition for dynamic

查看:98
本文介绍了“对象"不包含动态定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下描述方法.那返回动态结果.

I am using below describe method. That return dynamic result.

public static dynamic GetCouponDetailsbyCouponID(Guid couponID)
        {
            using (var loEntities = new Entities())
            {
                dynamic nonWinnerGift = (from nw in loEntities.CorporateNonWinnerGift
                                         join um in loEntities.Users on nw.UserID equals um.Id
                                         where nw.IsDeleted != true && nw.CouponID == couponID
                                         select new
                                         {
                                             FullName = (um.FirstName + " " + um.LastName),
                                                 Title = nw.Title,
                                                 Description = nw.Description,
                                                 LogoName = nw.LogoName,
                                                 CouponID = nw.CouponID,
                                                 IsDiscount = nw.IsDiscount,
                                                 Discount = nw.Discount,
                                                 Desclaiemer = nw.Desclaiemer
                                             }).SingleOrDefault();    
                return nonWinnerGift;
            }
        }

 dynamic expandDoObject = new ExpandoObject();

当我尝试访问"couponData.LogoName"时,抛出了动态运行时异常.请在下面找到我的例外"ClosetAuctions.dll中发生了'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException类型的第一次机会异常"其他信息:对象"不包含"LogoName"的定义"

When I am trying to access "couponData.LogoName" than thrown dynamic run-time exception. Please find below my exception "A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in ClosetAuctions.dll Additional information: 'object' does not contain a definition for 'LogoName'"

                var couponData = CorporateNonWinnerGiftBL.GetCouponDetailsbyCouponID(couponID);

                if (couponData != null)
                {
                    string fileName = couponData.LogoName;
                }

推荐答案

以下文章已回答"RuntimeBinderException".

"RuntimeBinderException" has already been answered on below articles please refer it.

尝试以下代码:

public static dynamic GetCouponDetailsbyCouponID(Guid couponID)
{
    using (var loEntities = new Entities())
    {
        var nonWinnerGift = (from nw in loEntities.CorporateNonWinnerGift
            join um in loEntities.Users on nw.UserID equals um.Id
            where nw.IsDeleted != true && nw.CouponID == couponID
            select new
            {
                FullName = (um.FirstName + " " + um.LastName),
                Title = nw.Title,
                Description = nw.Description,
                LogoName = nw.LogoName,
                CouponID = nw.CouponID,
                IsDiscount = nw.IsDiscount,
                Discount = nw.Discount,
                Desclaiemer = nw.Desclaiemer

             }).SingleOrDefault();

        dynamic d = new ExpandoObject();

        d.FullName = nonWinnerGift.FullName;
        d.Title = nonWinnerGift.Title;
        d.Description = nonWinnerGift.Description;
        d.LogoName = nonWinnerGift.LogoName;
        d.CouponID = nonWinnerGift.CouponID;
        d.IsDiscount = nonWinnerGift.IsDiscount;
        d.Discount = nonWinnerGift.Discount;
        d.Desclaiemer = nonWinnerGift.Desclaiemer;

        return d;
    }
}

这篇关于“对象"不包含动态定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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