logo
Tags down

shadow

another option instead using AsEnumerable() in linq EF, when using custom method in linq


By : Willem Desmet
Date : September 29 2020, 08:00 AM
like below fixes the issue Entity Framework needs to translate your query into a SQL query, which means it needs to know how to convert every part of it into SQL. Your query contains calling a RemoveA function, which Entity Framework doesn't know how to deal with. You can solve this by converting your code into
code :
class Program
{
    static void Main(string[] args)
    {
        string keyword = "m";
        using (TestingEntities1 db = new TestingEntities1())
        {
            var models = db.Teachers.Where(a => a.Name.Replace("a", " ").Contains(keyword));
            foreach (var item in models)
            {
                Console.WriteLine(item.Name);
            }
        }
    }
}


Share : facebook icon twitter icon

Linq. How to use AsEnumerable within Linq (sql syntax) query? EF4.1


By : Majid Ali
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , See two functionally identical queries below, sql and lambda version: , You will simply do this:
code :
var query (from a in context.Lines
           where a.LineId == SomeGuid
           select a).AsEnumerable();
var query =  (from a in Lines
              where a.LineId == SomeGuid
              select new {
                  LineId = a.LineId
              }).AsEnumerable()
              .Select(a => new Line { LineId = a.LineId });

LINQ to SQL into LINQ to Objects - switch via AsEnumerable or via ToList


By : victari0n
Date : March 29 2020, 07:55 AM
should help you out .ToList() will build a new List in memory and store all of the objects in it.
That is needless work; you should call .AsEnumerable().

Whether to use AsEnumerable() in LINQ or not?


By : user3878354
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further OK guys, I took notice of different points from all of you & came up with this:
code :
var Data = (from r in _context.PRD_ChemProdReq.AsEnumerable()
                    //where r.RecordStatus == "NCF"

                    join rf in _context.SYS_Store on (r.RequisitionFrom==null?0: r.RequisitionFrom) equals rf.StoreID into requisitionfrom
                    from rf in requisitionfrom.DefaultIfEmpty()

                    join rt in _context.SYS_Store on (r.RequisitionTo == null ? 0 : r.RequisitionTo) equals rt.StoreID into requisitionto
                    from rt in requisitionto.DefaultIfEmpty()

                    orderby r.RequisitionNo descending
                    select new PRDChemProdReq
                    {
                        RequisitionID = r.RequisitionID,
                        RequisitionNo = r.RequisitionNo,
                        RequisitionCategory = DalCommon.ReturnRequisitionCategory(r.RequisitionCategory),
                        RequisitionType = r.RequisitionType == "UR" ? "Urgent" : "Normal",
                        ReqRaisedOn = (Convert.ToDateTime(r.ReqRaisedOn)).ToString("dd'/'MM'/'yyyy"),
                        RecordStatus = (r.RecordStatus=="NCF"? "Not Confirmed": "Approved"),
                        RequisitionFromName = (rf==null? null: rf.StoreName),
                        RequisitionToName = (rt == null ? null : rt.StoreName)
                    });

Local method in Linq without AsEnumerable()


By : user7037891
Date : March 29 2020, 07:55 AM
wish help you to fix your issue You can divine your cipher text to 3 part,hashing,encryption,IV. When you want to querying and searching for a specific text, you can hash the plain text and search in cipher text part 1 for the hash and get your row.
This is the asp.net core code :
code :
 public static string CreateKey()
        {
            var alg = Aes.Create();
            alg.KeySize = 256;
            return Convert.ToBase64String(inArray: alg.Key);
        }
 public string EncryptAes(string inputText)
        {
            if (inputText == null) return null;
            var hashing = new Hashing(text: inputText);
            var hash = hashing.GetHash();
            var inputBytes = Encoding.UTF8.GetBytes(s: inputText);
            using (var ms = new MemoryStream())
            {
                var alg = Aes.Create();
                var pdb = new Rfc2898DeriveBytes(password: _key, salt: alg.IV);
                alg.Key = pdb.GetBytes(32);
                alg.IV = pdb.GetBytes(16);
                using (
                    var cs = new CryptoStream(stream: ms, transform: alg.CreateEncryptor(),
                        mode: CryptoStreamMode.Write)
                )
                {
                    cs.Write(buffer: inputBytes, offset: 0, count: inputBytes.Length);
                }
                return hash + Convert.ToBase64String(inArray: pdb.Salt) + Convert.ToBase64String(inArray: ms.ToArray());
            }
        }

        public string DecryptAes(string inputText)
        {
            if (inputText == null) return null;
            var inputBytes = Convert.FromBase64String(s: inputText.Substring(52));
            var pdb = new Rfc2898DeriveBytes(password: _key,
                salt: Convert.FromBase64String(s: inputText.Substring(28, 24)));

            using (var ms = new MemoryStream())
            {
                var alg = Aes.Create();
                alg.Key = pdb.GetBytes(32);
                alg.IV = pdb.GetBytes(16);

                using (
                    var cs = new CryptoStream(stream: ms, transform: alg.CreateDecryptor(), mode: CryptoStreamMode.Write)
                )
                {
                    cs.Write(buffer: inputBytes, offset: 0, count: inputBytes.Length);
                }
                return Encoding.UTF8.GetString(bytes: ms.ToArray());
            }
        }
 public string GetHash()
        {
            using (var sha1 = SHA1.Create())
            {
                var hashedBytes = sha1.ComputeHash(buffer: Encoding.UTF8.GetBytes(s: _text));
                return Convert.ToBase64String(inArray: hashedBytes).Replace(oldValue: "-", newValue: "");
            }
        }

        public string GetHashFromEncryption(string text)
        {
            return text.Substring(0,28);
        } 

In what scenario we have to use extension method as AsEnumerable() and ToList() in linq Query


By : Akkshay
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further The (string)s in this context is simply saying "cast the variable s as type string" - I'm guessing that GetSelectedFieldValues("ID") returns object, and you want a sequence of strings. There's actually a .Cast() that would have done that for you.
As for when you need AsEnumerable() - pretty rarely, actually - and probably not in this case. The key scenario is when it wouldn't be otherwise. Perhaps you explicitly want to treat IQueryable as IEnumerable (to force LINQ-to-Objects instead of query composition). Or maybe you're dealing with something like DataSet where the .Rows etc aren't actually IEnumerable for any T, and need help.
code :
var strings = grdLookupPracticeMultiple.GridView.GetSelectedFieldValues("ID")
                      .Cast<string>().ToList();
var strings = grdLookupPracticeMultiple.GridView.GetSelectedFieldValues("ID")
                      .ConvertAll(s => (string)s);
Related Posts Related Posts :
  • Submit Button is not working In Razor asp.net mvc
  • While loop multiple condition check with single variable
  • Inside a catch clause, how can I see an exception without a name
  • How I can use Certificate.pfx for windows exe build
  • I'm trying to detect that SQL Server Compact Edition is installed in a system or not
  • UWP Replace MainView with FullScreen Frame
  • How do I display the data of the "current user"?
  • AVX2 SIMD XOR not yielding performance improvements in .NET
  • Algorithm to find the closest time
  • Xamarin Form - How To store an image in PDF or JPEG Format in UWP
  • ModelState error: The value 'null' is not valid for nullable field
  • Pre Increment of an operator
  • MSTest Asserts fail with null reference
  • Getting random numbers after a simple math problem. Might be a local variable thing
  • Convert HTML to PDF using HTML Renderer using C# and XML to Pdf
  • Conversion failed when converting varchar value to datatype bit
  • How to edit an XML file in Streamingassets from my hololens
  • Naming a DispatcherTimer based on a string from another method?
  • How to call the default browser in the Hololens app
  • How do I close an IF statement if there is no more code to be executed with 'else'?
  • Unity3D: Is there a easy way to give a min/max to a value in the inspector?
  • The type or namespace name 'ICloudRecoEventHandler' could not be found
  • When compiling C# expression trees into methods, is it possible to access "this"?
  • Sort an array of strings in ascending order in C#
  • How detect is a method in a C# class is implementing a method from an interface?
  • How to parse a timespan in order to add it to a datetime?
  • Changing code from if-statement to switch-statement in C#
  • Linq GroupBy Clause not including items with zero count
  • How to determine the highest value in a list of properties
  • C# Custom Json.NET List serialization
  • Session Variable is null after using RedirectToAction
  • How to manipulate c# code programatically In .Net Core?
  • Modifying Windows System sounds
  • Is there a way to convert this powershell script to C#
  • Lists will show null even though assigned in constructor
  • Any way to have a `using` block that doesn't define a scope block?
  • How do I get a result from this mocked service?
  • async await losing response in c#
  • How can I pause an execution without using Thread.Sleep()
  • How to Stop In Azure Ad Authentication Sign Out ask for Which account do you want to sign out of?
  • Use operators with and without space in c#
  • Remove duplicates from comma separated list
  • Use a String variable as argument from if sentence
  • unity how to avoid scaling heritage when parenting?
  • Is there a way to do nested model binding with the [FromBody] attribute?
  • How to insert dynamic query into table using c#
  • Why Unit Testing Assert.AreEqual() method does NOT pick up my own Equals() method in the customized class
  • Unity Error: Feature 'out variable declaration'
  • What happens if my C# switch expression is non-exhaustive?
  • How Can I Select an ItemTemplate Based on a Value?
  • EF Class table name and column have same name
  • Substring issues - input string was not in a correct format
  • C# Asynchronously read data from a redirected StandardOutput
  • The code after await operation is not executing
  • Image FILL logic such as "Stretch.Uniform" of WPF
  • Why am I allowed to declare a variable with the same name?
  • Simplest way to display colored 3D boxes in winforms
  • Conventions on having both an API and MVC project in .NET Core solution
  • File upload .NET Core 'IFormFile' does not contain a definition for 'CopyToAsync' and no extension method
  • Deserialize only valid objects by ignoring errors
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk