I use the descriptive method below. This returns a 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();
When I try to access "couponData.LogoName" than a dynamic exception exception at runtime. Below you will find my exception "First closing exception 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; }
source share