Reading From a Text File in C#

To read a text file one line at a time you can do like this: using System.IO; using (var reader = new StreamReader(fileName)) { string line; while ((line = reader.ReadLine()) != null) { // Do stuff with your line here, it will be called for each // line of text in your file. } } … Read more

No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlServerCe.4.0’

After installing the EntityFramework.SqlServerCompact nuget package, check that your app.config contains the following (as per @ErikEJ’s comment above): <providers> <provider invariantName=”System.Data.SqlClient” type=”System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer” /> <provider invariantName=”System.Data.SqlServerCe.4.0″ type=”System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact” /> </providers> (You can leave the line for SqlClient even though you don’t really need it.)

Difference between Assembly.GetExecutingAssembly() and typeof(program).Assembly

Assuming program is in the executing assembly, they should both return the same value. However, typeof(program).Assembly should have better performance, since Assembly.GetExecutingAssembly() does a stack walk. In a micro benchmark on my machine, the former took about 20ns, while the latter was 30x slower at about 600ns. If you control all the code I think … Read more

ASP.net MVC Controller – Constructor usage

You are asking the right questions. A. It is definitely not appropriate to create this dependencies inside each action method. One of the main features of MVC is the ability to separate concerns. By loading up your controller with these dependencies, you are making the controller for thick. These should be injected into the controller. … Read more

How to handle hierarchical routes in ASP.NET Web API?

Configure the routes as below. The {param} is optional (use if you need): routes.MapHttpRoute( name: “childapi”, routeTemplate: “api/Parent/{id}/Child/{param}”, defaults: new { controller = “Child”, param = RouteParameter.Optional } ); routes.MapHttpRoute( name: “DefaultApi”, routeTemplate: “api/{controller}/{id}”, defaults: new { id = RouteParameter.Optional } ); Then call the child APi as /api/Parent/1/child The parent can be called simple … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)