Posts

How to view the SQL generated query by the Entity Framework

Image
If we want to write log file of Entity Framework query in EF 6 we can follow this step

Step 1: Open EDMX cs file and copy the code:


protected override void OnModelCreating(DbModelBuilder modelBuilder) { Database.Log = (query) => Debug.Write(query); }

Step 2 : write log on your Entity Framework query


refauthrequests refauthEntity = EM_Refauthrequests.ConvertToEntity(vsspoAuditModel); _db.refauthrequests.Add(refauthEntity); _db.Database.Log = queryLog => { Debug.Print(queryLog); // Debug.Print will show the output on visual studio output window You can write log using queryLog value }; _db.SaveChanges();

If you set debugger you will see the output window




SQL Generate Date from given date range

Image
WITH Dates AS ( SELECT [Date] = CONVERT(DATETIME,'1-1-2017') UNION ALL SELECT [Date] = DATEADD(DAY, 1, [Date]) FROM Dates WHERE Date < '12-31-2017' ) SELECT [Date] FROM Dates OPTION (MAXRECURSION 1000)


Run all SQL files from a folder

Run all SQL files from  a folder you can follow the process that will save your time for executing SQL script


Copy this code in a notepad file and change the Server, Database, Username And Password value as your self and save it as a .bat file. copy the file in your SQL script folder and run this bat file.

REM REM development environment only!! REM pause for %%G in (*.sql) do sqlcmd /S "192.168.10.139\SQLEXPRESS" /d "VSSPORT_DEV" -U "atiour" -P "atiour" -i"%%G" pause REM REM All Script Run Successfully REM



nopcommerce gmail and godaddy email setting

Image
Gmail Setting

1. Login to your gmail account.
2. Visit this page https://accounts.google.com/DisplayUnlockCaptcha and click on button to allow access.
3. Visit this page https://www.google.com/settings/security/lesssecureapps and enable access for less secure apps.
4. Login to your nopCommerce admin portal and visit this page http://website_name.com/Admin/EmailAccount/List and click edit  and click to delete the account.
5. Now use following details:
   Email address: youraddress@gmail.com
   E display name: your website name
   Host: smtp.gmail.com
   User: youraddress@gmail.com
   Password: password, remember to click change password button if you are editing any existing account
   SSL: tick to select it
   Use default credentials: uncheck, do not select it
6. Click on save button above.
7. Test the mailing by entering your email id and click on send test email button.




Godaddy Setting



the type 'system Attribute' is defined in an assembly that is not referenced.You must add a reference to assembly 'system.runtime, version=4.0.0.0, culture=neutral, PublickKeyToken=b03f5f7f11d50a3a'

In this error message,{assembly}represents one of the actual files that is found in the "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Facades" folder.

To resolve this problem, install the updated version of the Microsoft .NET Framework 4.5.2 Developer Pack. For download information


https://support.microsoft.com/en-us/help/2901951

During Installation if you get update windows option then update the windows it will resolve your problem.


C# dynamic linq query

In to Linq query, we can use dynamic query:

public List<Insplan> GetInsplanLookupList(string planName = null, string binNo = null, string procCtrl = null) { var query = (from i in _db.insplan orderby i.cinsplanname ascending select i).AsQueryable(); if (!string.IsNullOrWhiteSpace(planName)) query = query.Where(x => x.cinsplanname.StartsWith(planName.Trim())); if (!string.IsNullOrWhiteSpace(binNo)) query = query.Where(x => x.cbinno.StartsWith(binNo.Trim())); if (!string.IsNullOrWhiteSpace(procCtrl)) query = query.Where(x => x.cprocctrlno.StartsWith(procCtrl.Trim())); return (from q in query join ic in _db.inscomp on q.inscompid_FK equals ic.inscompid_PK into ic_joined from ic in ic_joined.DefaultIfEmpty() join cl in _db.clinic on q.clinicid_FK equals cl.clinicid_PK into cl_joined from cl in cl_joined.De…

mvvm double click event in listview

If you want to get the double click event on a listview item you can try with this code;



<ListView Grid.Row="0" Grid.RowSpan="3" Grid.Column="0" Width="250" Height="200" HorizontalAlignment="Stretch" VerticalAlignment="Top" AlternationCount="2" BorderBrush="#FFA8CC7B" ItemContainerStyle="{StaticResource alternatingStyle}" ItemsSource="{Binding FromPayerNameList}" SelectedItem="{Binding SelectedFromPayer, Mode=TwoWay}"> <ListView.ItemTemplate> <DataTemplate> <TextBlock Width="{Binding Path=ActualWidth, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}" Text="…