Posts by Leonel Sanches da Silva • 88,623 points
2,010 posts
-
2
votes2
answers2142
viewsA: Bring certain field, by MAX(ID)
If you simply want to bring the largest table id, only this solves: Select MAX(ID) from tabela; After all, Id is unique and does not need to group values. If you need to bring another field based on…
sql-serveranswered Leonel Sanches da Silva 88,623 -
2
votes3
answers4347
viewsA: Check if the item exists in a List<>
The correct form is using Any: if (!listLoteRecla.Any( x => x.est_lote.Equals(dtDados.Rows[i]["est_lote"].ToString()) && x.id_log_unidade.Equals(dtDados.Rows[i]["id_log_unidade"])…
-
2
votes2
answers569
viewsA: Relationships in Viewmodel with EF
If the idea is to separate by Viewmodels so that each Viewmodel is represented by a Partial, the reasoning is wrong. The idea of separating Models (or Viewmodels) is for the principle of…
-
3
votes1
answer2846
viewsA: Error: Could not load file or Assembly 'Dotnetopenauth.Aspnet' or one of its dependencies
Try two more things: Delete the directory /bin of the project; Delete the directories inside C:\Users\SeuUsuario\AppData\Local\Temp\Temporary ASP.NET Files. Also delete directories below the…
-
0
votes2
answers761
viewsA: Argued tofrangeexception with Entity
If arquivo.ArquivoVersoes is null, you need to use a code that prevents this: internal void AddArquivo(Model.Arquivo arquivo) { using (var ctx = new TestEntities()) { var versao =…
-
1
votes1
answer179
viewsA: Access App_data content through the business layer (Classlibrary)
Yes, it is feasible, because who executes the class library is your web project, but try to use it as follows: var appData= System.Web.HttpContext.Current.Server.MapPath("~/App_Data/...");…
-
2
votes1
answer2651
viewsA: Changed RU context, but without updating database structure
How it works? SetInitializer as null indicates to the Entity Framework that the database has no boot class. By default, it is MigrateDatabaseToLatestVersion, which executes all the Migrations…
-
5
votes1
answer4920
viewsA: Building Customizable ASP.NET MVC Menu
Considering that the license will not be tied to the user, from what I understood of your question, a correct approach would be a home solution. Models public class MenuItem { [Key] public int…
-
1
votes1
answer124
viewsA: Is it possible to do Phonegap together with Asp.Net MVC 5 in a single project?
I would like to know if there is the possibility of making a DDD Design Solution with two View Ports, one for mobile application using Phonegap and the other MVC 5. There is. To set your project to…
-
1
votes1
answer286
viewsA: How to remove querystring Returnurl?
I do not recommend doing this because it is a major loss of functionality (in case, redirect the user to the page from which it came and which was not authorized), but I will demonstrate how to…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
1
votes1
answer308
viewsA: Entity Framework does not update my database
There are some ways to solve. 1. Revert the bank to a Migration that you know works This is the case for projects with manual generation of Migrations. Use the following command: Update-Database…
entity-framework-6answered Leonel Sanches da Silva 88,623 -
0
votes1
answer513
viewsA: How to load a partialview for an AJAX request?
In your case, don’t use it like that: Html.RenderPartial("_ContatoEmailFields"); Use like this: Html.Partial("_ContatoEmailFields"); I explain this in this reply.…
-
11
votes1
answer898
viewsA: Is it correct to save multiple entities at the same time in the ASP.NET MVC Controller?
I will base my answer by not mentioning a correct way, but a way performative how to do this. I see this with severe concern: public ActionResult Create(Animal animal, Atividade atividade,…
-
3
votes1
answer614
viewsA: Switch HTACCESS to Web.config
Yes, it is possible. There is this guide on the IIS page for the translation of the contents of a file .htaccess in an archive Web.config. It is not worth digging into the examples contained on the…
-
1
votes1
answer288
viewsA: Joint foreign key between index field and a possible string
In your place, I would make an N to N association with a CHECK CONSTRAINT to check that only one of the Fks is filled: CREATE TABLE ENDERECO ( ENDERECO_ID INT PRIMARY KEY IDENTITY, STATUS…
-
1
votes1
answer418
viewsA: How to get bank reports through web application?
For this answer I will have to give general lines, because the detailed implementation would be very extensive. What we have in your question is a Stored Procedure In Microsoft SQL Server it is…
-
5
votes5
answers2024
viewsA: Return inside Try... catch does not work
This is because the code may never reach return in fact. Using your own code, for example: try { //Instâncias e Inicializalções vcmpExecutor = new WFExecutor(); vcmpAnalise = new WFAnalise();…
-
1
votes2
answers153
viewsA: Alternative to the use of new when implementing methods that return this in child classes
I took the following test: using System; public class Pai { protected string PropriedadeA { get; set; } public Pai Metodo1(int valor) { //Vários procedimentos feitos aqui PropriedadeA = "Resultado…
-
6
votes2
answers718
viewsA: Entity Framework or Stored Procedure
In the original question there was exactly this part in the content. For historical reasons, I am keeping this piece of the old question because it is pertinent to the rest. I wonder if Stored…
-
2
votes2
answers7643
viewsA: Application Security Change for Medium Trust
For newer Frameworks, Microsoft is discouraging Medium Trust in favour of isolation by operating system level, as described in this supporting item for newer Frameworks like Owin, in your case.…
-
2
votes1
answer294
viewsA: Inserting data into sql server table
The mistake is in yours INSERT. You named the fields being entered but did not include the field id_observacao that by its modeling is NOT NULL. See below the correct: INSERT INTO…
sql-serveranswered Leonel Sanches da Silva 88,623 -
2
votes2
answers2831
viewsA: Format date (dd/MM/yyyy)
Make the change in SQL, since you are using SQL manual for the update: myCommand = "UPDATE DoctorBasic SET " & _ "DOB = convert(datetime, '" & Convert_Null(DGV1(9,…
-
2
votes1
answer1628
viewsA: Inputmask for Displayfor
Use something simpler. A ToString() formatted solves everything: @Model.sTelefone.ToString(@"0000\-0000") No need to format by Javascript because the field will appear static.…
-
13
votes3
answers10666
viewsA: Error in publishing application to OSI
Run the following sequence of steps to check your server configuration: In your Windows, go to Control Panel > Programs and Resources > Enable or disable Windows Features; Locate the "Internet…
-
1
votes2
answers486
viewsA: Asp.net mvc Bad Request
Set in your file web.config the pages to be returned for each error code. <configuration> <system.web> <customErrors mode="On" redirectMode="ResponseRewrite"> <error code="404"…
-
1
votes1
answer697
viewsA: Load external scripts in modal being loaded via ajax
The elegant way is by putting a section for Scripts in the Modal Layout: @RenderSection("scripts", required: false) Thus, for each file of View other than a Partial, just call the Views with the…
-
3
votes1
answer127
viewsA: Best practices when using Sqlcommand? Text or Storedprocedure?
In this scenario it is faster to run the Storedprocedure or Text? Storedprodecure is faster. According to that Article, use Text makes the object call sp_executesql, which creates certain overhead…
-
1
votes1
answer55
viewsA: How to develop Check-In policies only after a Get Last Version in TFS 2012?
There is the TFS Checkin Policy, which can be installed as a plugin for Visual Studio. Just install on the machine and use TFS normally. From the 2010 version of Visual Studio, you can perform the…
team-foundation-serveranswered Leonel Sanches da Silva 88,623 -
5
votes2
answers297
viewsA: Best way to do an Action that does not return data
Is using ActionResult same. The problem is that EmptyResult returns nothing even, or requisition code: public ActionResult MinhaActionSucesso() { // Antes do MVC5 return new…
-
1
votes1
answer269
viewsA: Web Forms for MVC 5
Is there a possibility to do this type of integration? Or is it more feasible to redo the application in MVC? No, because the requisition handling architecture is completely different. Rewriting the…
-
2
votes1
answer187
viewsA: What is Rootdse
Is there some form of interaction with rootDSE and some programming language? There are several. In this article posted by @Pablovargas as a comment, there are examples in C#, VB.NET and Ironpython.…
-
1
votes3
answers414
viewsA: Validation using Remote in the "Parent" class
Remote supposes that the validation is in Controller, not in the Model. According to your question, you own a ValidationController which has the validation method, which is correct if the intention…
asp.net-mvc-5answered Leonel Sanches da Silva 88,623 -
2
votes1
answer309
viewsA: Retrieve information about which Tables/Procedures/Views are most accessed in SQL SERVER
Use the following function: CREATE FUNCTIOn fn_TablesLastUpdateDate(@Date NVARCHAR(20)) RETURNS @table TABLE(TableName NVARCHAR(40), LastUpdated Datetime) AS BEGIN IF(@Date='') OR (@Date Is Null) OR…
-
5
votes1
answer239
viewsA: Toupper() with accents
Try specifying culture information by passing an object CultureInfo for the method ToUpper: insira o código @Html.DisplayFor(model =>…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
4
votes1
answer1699
viewsA: How to save the same object in the database using entityFramework . net MVC?
No need for methods Commit and Adicionar. Also remove the SaveChanges from inside the loop. Simply use: usuarioVM.ContatoUsuarios = ContatoUsuarioRepositorio.ObterContatoSemUsuario(); //obtenho os…
-
1
votes3
answers877
viewsA: Asp.net serving statics files
As I have answered here, this is the way incorrect to make static files available in your application. Block access via GET method of HTML files from the /data folder? Yes, creating in your…
-
1
votes1
answer279
viewsA: Use Session as Query Parameter
Make a Helper: public static class SessionHelper { public static int Contrato { get { return (int)HttpContext.Current.Session['Contrato']; } set { HttpContext.Current.Session['Contrato'] = value; }…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
1
votes1
answer375
viewsA: Translation of MVC routes
1. Make a Resource file for routes only In this case, program your system so that each Resource String is the name of a Controller or the name of a Action. It’s okay to repeat. 2. Make a route file…
-
0
votes2
answers87
viewsA: Add new Controller
Before creating the Controller, make sure that there is no line with something like this in the event OnModelCreating: modelBuilder.Configurations.Add(new UsuarioConfiguration());…
-
2
votes2
answers761
viewsA: Save data to a Viewbag
Alternatively to @Paulohdsouza’s reply, no need to use ExpandoObject to return a database object. C# dynamic inference already solves this problem: public ActionResult Index() { var lista =…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
2
votes2
answers688
viewsA: Save data to a "Global Viewable"
Do an assignment to Session in your Controller: public ActionResult Exemplo(int Contrato) { HttpContext.Current.Session["Contrato"] = Contrato; ... } Reclaiming the value of: public ActionResult…
asp.net-mvcanswered Leonel Sanches da Silva 88,623 -
7
votes1
answer134
viewsA: Authorization in class Ibraries
I would like to know, what is the best approach to authorization control in these dll’s. It is possible to use Identity? Possible, but Identity was designed for the MVC architecture initially. It…
-
6
votes1
answer226
viewsA: Why are relationships in the Entity Framework code first pointed with Icollection<T>?
Why relationships in Entity Framework code first are pointed with Icollection? Because the lazy load of the Entity Framework puts in this property a dynamic proxy, which represents an object that…
-
1
votes2
answers104
viewsA: Batch deletion using Linq
There is the method DeleteAllOnSubmit. I’ve never used this method, but he’s kind of like this: var receitas = (from r in contexto.Receitas where r.ProjetoId == 100 && r.ItemId == 5 select…
-
3
votes1
answer1195
viewsA: Hide Actionlink parameter
There are some techniques you can use. Use a Slug; Use a finder; Use another way to locate the record only, such as a generated Id. Slug Slug is a descriptive identifier of the record. For example,…
-
1
votes2
answers679
viewsA: Problems with Modal
Use a Lightbox plugin, such as Lightbox for MVC: https://www.nuget.org/packages/jQuery.mvc.LightBox/ See examples of use here.…
-
6
votes3
answers2439
viewsA: What is the real advantage of using a Callback and what is thread/multithread?
What’s the real advantage of using a Callback? The advantage is to be able to define a parameter in a class that is actually a function. This exempts the programmer from a framework, for example,…
-
4
votes3
answers1060
viewsA: Implementation of generic CRUD
It’s right to implement like this? No. The approach is incorrect for collection manipulation as it makes the record manipulation procedure complex and poor in performance. You are defining a class…
-
0
votes3
answers4561
viewsA: Validate Datetime on the client
The resolution script is in two answers I’ve written: Problem storing decimal values in SQL Server Jquery validate does not validate correctly…
-
1
votes1
answer54
viewsA: Way to save only two information
Since it is an update, it is wrong to add the object in context. You need to retrieve the old object and update field by field: public ActionResult Controle([Bind(Include =…