Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 2.26 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ASP.Net C# LINQ to Entities Lambda expression casting result
  2. public IEnumerable<int> addResApp(string RestName, string RestStreet, string RestCity, string RestZip, string RestPhone, string ContactFname, string ContactLname, string ContactEmail, string ContactPhone)
  3.     {
  4.         APP_REST appRest = new APP_REST();
  5.         appRest.APP_REST_NAME = RestName;
  6.         appRest.APP_REST_STREET = RestStreet;
  7.         appRest.APP_REST_CITY = RestCity;
  8.         appRest.APP_REST_ZIP = RestZip;
  9.         appRest.APP_REST_PHONE = RestPhone;
  10.         appRest.APP_CONTACT_FNAME = ContactFname;
  11.         appRest.APP_CONTACT_LNAME = ContactLname;
  12.         appRest.APP_CONTACT_EMAIL = ContactEmail;
  13.         appRest.APP_CONTACT_PHONE = ContactPhone;
  14.         db.AddToAPP_REST(appRest);
  15.  
  16.         //Return the ID of the added record
  17.         var AppRestID = from APP_REST in db.APP_REST
  18.                  group APP_REST by APP_REST.APP_CODE into grp
  19.                  select grp.OrderByDescending(g => g.APP_CODE).Last();
  20.         return AppRestID;
  21.     }
  22.        
  23. var appRestId = from APP_REST in rests
  24.                         group APP_REST by APP_REST.APP_CODE
  25.                         into grp
  26.                         orderby grp.Key descending
  27.                         select grp.Key;
  28.        
  29. public class DLaddRestApp
  30. {
  31.  
  32.     RestaurantsEntities db = new RestaurantsEntities();
  33.  
  34.     public IEnumerable<int> addResApp(string RestName, string RestStreet, string RestCity, string RestZip, string RestPhone, string ContactFname, string ContactLname, string ContactEmail, string ContactPhone)
  35.     {
  36.         APP_REST appRest = new APP_REST();
  37.         appRest.APP_REST_NAME = RestName;
  38.         appRest.APP_REST_STREET = RestStreet;
  39.         appRest.APP_REST_CITY = RestCity;
  40.         appRest.APP_REST_ZIP = RestZip;
  41.         appRest.APP_REST_PHONE = RestPhone;
  42.         appRest.APP_CONTACT_FNAME = ContactFname;
  43.         appRest.APP_CONTACT_LNAME = ContactLname;
  44.         appRest.APP_CONTACT_EMAIL = ContactEmail;
  45.         appRest.APP_CONTACT_PHONE = ContactPhone;
  46.         appRest.APP_DESC_CUISINE = "";
  47.         db.AddToAPP_REST(appRest);
  48.         db.SaveChanges();
  49.  
  50.         var appRestId = from APP_REST in db.APP_REST
  51.                 orderby APP_REST.APP_CODE ascending
  52.                 select APP_REST.APP_CODE;
  53.  
  54.         return appRestId;        
  55.     }