Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all 1698 articles
Browse latest View live

how to set the length of column for text in mysql

$
0
0

Hi All,

I am learning  asp.net core + entity framework core + mysql  to build cross-platform solution. I use Entity Framework core with code first and I find that the property with string type in class is mapped to "text" in mysql database, but i want to know that how to set the length of column in mapping table.


select specific records without knowing a selector

$
0
0

Hi

I have a model something like

model
{
public int id {get;set;} public int selector [get;set;} public string Somefield {get;set;}
public bool status {get;set;} } new model {id = 1, selector = 1, Somefield = "a", status = false} new model {id = 2, selector = 2, Somefield = "b", status = false} new model {id = 3, selector = 1, Somefield = "c", status = false} new model {id = 4, selector = 3, Somefield = "a", status = false} new model {id = 5, selector = 4, Somefield = "a", status = false} new model {id = 6, selector = 7, Somefield = "a", status = false} new model {id = 7, selector = 2, Somefield = "d", status = false}
new model {id = 8, selector = 1, Somefield = "a", status = false}

now I want do a search for Somefield = "a", which is easy enough, this would return 4 records, however I only want to return one set of selectors without knowing the selector value at the time of search.

So my brain is thinking order by selector, grab first selector, but I don't know how to grab the first selector only.

Ay suggestions would be appriciated.

Navigation Property

$
0
0

I am struggling trying to figure out just exactly what a navigation property is used for. I read this sentence in an article about navigation properties....Navigation properties are shortcut properties that are used to locate the entities at theends of an association in a model. I dont understand what is meant by ends of an association, does this mean if a model has a virtual ICollection property?

Retrive the TD innertext value

$
0
0
<div>hi,</div> <div> </div> <div>I have the below HTMl and i need to get the Available QTY value 10.000 as a result . Needs to do a xpath in c# for geting the result.</div>

I have tried the below xpath but i couldnt get the result.  Any help is appreciated.

using HtmlAgilitypack;

HtmlNode node = doc.DocumentNode.SelectSingleNode("//td[b[. = 'Available Qty :']]/following-sibling::td");

<html>
<head>
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<link href="/public/vista/york.css" type="text/css" rel="stylesheet">
</head>
<form name="myform" method="post">
<input type="HIDDEN" name="PLANT" value="">
<input type="HIDDEN" name="session_id" value="ZiAlfPry4VkUj2*wTbMql***VISTA312111$-21~-19868108">
<input type="HIDDEN" name="user_id" value="vijay">
<table border="0" width="620">
    <tr>
        <td class="title" colspan="4">
            Product Availability     
        </td>
    </tr>
    
    <tr>
        <td class="text" colspan="4">
            <img border="0" src="/public/bc/icons/s_b_info.gif">
            &nbsp;Quantities reflect forecasted production within time periods displayed       <br>
            <img border="0" src="/public/bc/icons/s_b_info.gif">
            &nbsp;For any questions or concerns regarding your product availability please contact your Customer Service Representative at 800-536-6112             
        </td>
    </tr>
    <tr class="text">
        <td colspan="4">
            &nbsp;
        </td>
    </tr>
    
    <tr class="text">
        <td width="20%">
            <b>Customer ID     :</b>
        </td>
   <td width="30%">
       0010015272
   </td>
   <td width="20%">
       <b>Customer Name     :</b>
   </td>
   <td width="30%">
       AIR COND. UTILITIES.
   </td>
    </tr>
    <tr class="text">
        <td>
       <b>Item Number     :</b>
   </td>
   <td>
       ND120C00C6AAA3
   </td>
   <td>
       <b>Item Description     :</b>
   </td>
   <td>
       10T_EVAP_230/460-3-60_R410A_
   </td>
    </tr>
    <tr class="text">
        <td>
            <b>Dimensions     :</b>
        </td>
        <td>
            L030:W056:H065 - IN
        </td>
        <td>
            <b>Price Family     :</b>
        </td>
        <td>
            2720
        </td>
    </tr>
    <tr class="text">
        <td valign="top">
            <b>Weight     :</b>
        </td>
        <td valign="top">
            562.000 &nbsp;(LB)
        </td>
        <td>
            <b>UPC Code     :</b>
        </td>
        <td>
            883982733421
        </td>
    </tr>
    <tr class="text">
        <td valign="top">
            <b>Ship From Plant     :</b>
        </td>
        <td valign="top">
            US UPG Norman
        </td>
        <td colspan="2" valign="top">
            <table border="0">
                
                            <tr class="text">
                                <td class="tableCommon">
                                    <b>Brand     </b>
                                </td>
                                
                                    <td class="tableCommon">
                                        <b>List Price     </b>
                                    </td>
                                
                                
                                    <td class="tableCommon">
                                        <b>Net Price     </b>
                                    </td>
                                
                                
                                    <td class="tableCommon">
                                        <b>Discount       </b>
                                    </td>
                                
                            </tr>
                            
                        <tr class="text">
                            <td>
                                YORK
                            </td>
                            
                            <td align="right">
                                5330.00 
                            </td>
                            
                            
                            <td align="right">
                                2132.00 
                            </td>
                            
                            
                            <td align="right">
                                60.00-
                            </td>
                            
                        </tr>
                    
            </table>
        </td>
    </tr>
    <!--
    <tr class="text">
        <td colspan="4">
            <b>Replenishment Lead Time     :</b>&nbsp;
            16 &nbsp;
            <b>Factory Working Days     </b>
        </td>
    </tr>
    -->
<!-- begin of changes for task 3536 akumars11 16oct2007 -->
<!--  <td colspan="2"></td> -->
    <tr class="text">
        <td>
            <b>Min. Order Quantity :</b>
        </td>
        <td>
            0.000 
        </td>
 <!-- begin of changes for task 3536 akumars11 16oct2007 -->
    <tr class="text">
        <td>
    <!-- Begin of changes for SM 4000008069 (Change the name balance on hand to available qty) -->
            
            <font size='3'> <b>Available Qty          :</b> </font>
              <!-- Insertion for SM 4000008069-->
            <!-- End of insertion for SM 4000008069 -->
        </td>
        <td>
            
            <font size='3'> 10.000  </font>
               <!-- End of insertion for SM 4000007790 -->
        </td>
     </tr>
        <!-- (Add current lead time and delivery date) -->
    <!--insertion for SM 4000007790 -->
    <tr class="text">
        <td>
            <font size='3'> <b>Current Lead Time          :</b> </font>
        </td>
        <td>
            <font size='3'> 26 Days </font>
        </td>
        <!-- Display the traffic light based on standard time and current lead time difference)  -->
        <td>


        
        <img src="flash_red.gif" border="0" width="70" height="80">
        


        </td>
    </tr>
    <tr class="text">
        <td>
            <font size='3'> <b>Est. Delivery Date          :</b> </font>
        </td>
        <td>
            <font size='3'> 2018/03/17 </font>
        </td>
    </tr>
     <!-- Insertion for SM 4000007790-->
   <!-- End of insertion for SM 4000008069 -->
   
    <tr class="text">
        <td>
        
        <font size='3'><b>ABC indicator:</b></font>
          <!-- End of Insertion for SM 4000007790-->
        </td>
        <td>
        
        <font size='3'>A</font> <!-- Font added for SM 4000007790 -->
          <!-- End of Insertion for SM 4000007790-->
        </td>
  <!-- Begin of changes for SM 4000007790 -->
    </tr>
     
     <tr>
        <td class="text" colspan="4">
            <font color='red'>*If Requested Delivery Date is earlier than Est. Delivery Date contact your Order Services Account Manager for confirmation.                                                              </font>
        </td>
     </tr>
     <tr>
        <td class="text" colspan="4">
             <font color='red'>*Deliveries requested less than 15 days are subject to standard freight policies and Lead Time surcharges.</font>
        </td>
     </tr>
     
  <!-- End of changes for SM 4000007790-->
  <!-- begin of changes for SM 4000004032 -->
 <!--Begin of insertion for SM 4000007790-->
 <tr>
    
    <td>
    <table border="2">
       <!--Insertion for SM 4000007790-->
               <tr class="text">
                     <td class="tableCommon">
                        <b>ABC indicator</b>
                      </td>
                      <td class="tableCommon">
                        <b>Description          </b>
                       </td>
                       <td class="tableCommon">
                           


                               <b>Standard Lead Time  </b>
                           
                           <!-- End of changes for SM 4000007790-->


                        </td>
               </tr>
            


                        <tr class="text">
                            <td>
                                A
                            </td>
                            <td align="left">
                                Make to Stock
                            </td>
                            <td align="left">
                                15
                            </td>
                        </tr>
               


                        <tr class="text">
                            <td>
                                B
                            </td>
                            <td align="left">
                                Assemble to Order
                            </td>
                            <td align="left">
                                30
                            </td>
                        </tr>
               


                        <tr class="text">
                            <td>
                                C
                            </td>
                            <td align="left">
                                Make to Order
                            </td>
                            <td align="left">
                                45
                            </td>
                        </tr>
               


                        <tr class="text">
                            <td>
                                D
                            </td>
                            <td align="left">
                                Obsolete, Discontinued
                            </td>
                            <td align="left">
                                15
                            </td>
                        </tr>
               


                        <tr class="text">
                            <td>
                                P
                            </td>
                            <td align="left">
                                Phased Out, Availability limited to current stock
                            </td>
                            <td align="left">
                                15
                            </td>
                        </tr>
               


                        <tr class="text">
                            <td>
                                T
                            </td>
                            <td align="left">
                                Coated Coil
                            </td>
                            <td align="left">
                                45
                            </td>
                        </tr>
               


                        <tr class="text">
                            <td>
                                V
                            </td>
                            <td align="left">
                                Vendor Direct ship
                            </td>
                            <td align="left">
                                45
                            </td>
                        </tr>
               
            </table>
        </td>
  <!-- end of changes for SM 4000004032 -->
   </tr>
   
    


    


    <!--
    <tr class="text">
        <td colspan="4">
            &nbsp;
        </td>
    </tr>
    <tr class="text">
        <td colspan="4">
        
            &nbsp;&nbsp;<B>Summary     </B>&nbsp;&nbsp;
        
        
                &nbsp;&nbsp;
                <INPUT id=button2 type=submit value="US UPG Norman" name="onInputProcessing(1001)">
                &nbsp;&nbsp;
            
                &nbsp;&nbsp;
                <INPUT id=button2 type=submit value="US UPG Wichita" name="onInputProcessing(1002)">
                &nbsp;&nbsp;
            
                &nbsp;&nbsp;
                <INPUT id=button2 type=submit value="US UPG Source 1" name="onInputProcessing(1003)">
                &nbsp;&nbsp;
            
                &nbsp;&nbsp;
                <INPUT id=button2 type=submit value="US VRF Line of Business" name="onInputProcessing(1011)">
                &nbsp;&nbsp;
            
                &nbsp;&nbsp;
                <INPUT id=button2 type=submit value="Small Tonnage Chillers" name="onInputProcessing(1012)">
                &nbsp;&nbsp;
            
                &nbsp;&nbsp;
                <INPUT id=button2 type=submit value="" name="onInputProcessing(0165)">
                &nbsp;&nbsp;
            
        </td>
    </tr>
    -->


<!-- Begin of comment for SM 4000008069 -->
  <!-- Insertion for SM 4000007790 -->
    


<!-- End of comment for SM 4000008069 -->
    <tr class="text">
        <td colspan="4">
            <hr>
        </td>
    </tr>
    <tr>
        <td class="text">
            <b>Item Number     </b>
        </td>
        <td class="text">
            <input maxlength="18" size="18" name="txtitemnumber" value="ND120C00C6AAA3">
        </td>
        <td colspan="2" class="text">
            <input id="button4" type="submit" value="    Download to Excel           " name="onInputProcessing(submit)">
            &nbsp;
            <input id="button4" type="submit" value="Search " name="onInputProcessing(search)">
        </td>
    </tr>
    
    <tr>
        <td colspan="3" class="text" align="center">
            
                <input id="button1" type="submit" value="Previous - ND120C00C5AZZ3" name="onInputProcessing(prev)">
            
            &nbsp;
            
                <input id="button4" type="submit" value="Next - ND120C00C6AZZ3" name="onInputProcessing(next)">
            
        </td>
        <td></td>
    </tr>
    
    
    
    <tr class="TEXT">
        <td class="text" colspan="4">
            <br>
            <input id="button3" type="submit" value="Back " name="onInputProcessing(back)">
        </td>
    </tr>
    <tr class="text">
        <td class="smallstatementtext" colspan="4" align="right">
            100
        </td>
    </tr>
</tr></table>
<input type="hidden" name="pl" value="1001;1002;1003;1011;1012;0165">
<input type="hidden" name="slsorg" value="US15">
<input type="hidden" name="txtqtyreq" value="999999">
<input type="hidden" name="nxtMdl" value="ND120C00C6AZZ3">
<input type="hidden" name="prvMdl" value="ND120C00C5AZZ3">
</form>


</html>

Thanks

vj

Entity Framework .edmx file or Entity Data Model XML file

$
0
0

I was wondering does anyone know why when you right click on the edmx file it does not show update model from database? Thanks !

Many To many relationship creating error - cycles or multiple cascade paths

$
0
0

I am developing a code-first MVC application in Visual Studio 2013 with EF 6.2 and MVC 5.2.

I have what I think is a standard many to many relationship in the model between Audit and Audit_Measure i.e an Audit can have many Audit_Measures and an Audit_Measure can have many Audits. However, both can be created without the other i.e an Audit does not need an Audit_Measure and a Audit_Measure does not need an Audit.
Audit_Measure is also in a one to many relationship with Audit_Measure_Assessment.

Here is the Model:

   [Table("TRACS.Audit")]
    public class Audit
    {  
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Name = "Id", AutoGenerateField = true)]
        [DisplayInReportsAttribute]
        public int Audit_Id { get; set; }
....
        [Display(Name = "NoDisplay", AutoGenerateField = false, Order = 2)]public virtual ICollection<Audit_Measure> Audit_Measures { get; set; }   
    }
 [Table("TRACS.Audit_Measure")]
    public class Audit_Measure
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        [Display(Name = "Id", AutoGenerateField = true)]
        public int Audit_Measure_Id { get; set; }
[Display(Name = "NoDisplay", AutoGenerateField = false, Order = 1)]public virtual ICollection<Audit> Audits { get; set; }

        [Display(Name = "NoDisplay", AutoGenerateField = false, Order = 2)]public virtual ICollection<Audit_Measure_Assessment> Audit_Measure_Assessments { get; set; }

    }

To the context I have added fluent API as follows:

 modelBuilder.Entity<Audit>()
                .HasMany(c => c.Audit_Measures).WithMany(i => i.Audits)
                .Map(t => t.MapLeftKey("Audit_Id")
                    .MapRightKey("Audit_Measure_Id")
                    .ToTable("Audit_Audit_Measure", "TRACS")); 

On the very first run of the application, I am receiving the error:
"Introducing FOREIGN KEY constraint 'FK_TRACS.Audit_Audit_Measure_TRACS.Audit_Measure_Audit_Measure_Id' on table 'Audit_Audit_Measure' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint."

After consulting Professor Google, I can't quite figure out what it is exactly complaining about and where the multiple cascade paths issue comes into it.
In addtion, I am not sure where to specify ON DELETE NO ACTION or ON UPDATE NO ACTION, as the database is not created yet.

Thanks for considering.

LINQ to retrieve the number of users registered per month

$
0
0

Hi,

I have a user table, which contains the users registered to an application.

I need to retrieve the list  of number of users registered each month . The month should be taken from the CreatedOn field in the same table.

I need to generate report based on this data. so i need the output as follows

UserCount    Month

2                    Jan

3                   Feb

I am using mvc5 with EF6 to retrieve  the data. How can i retrieve the data in the above format using linq/lambda expression.

Entity Framework "Database First" not generating Foreign keys (MYSQL)

$
0
0

Hi!

my table has some foreign key constraints. except for one constraint all the other relationships are fine.

from MySQL workbench, I tried with reverse engineering to see all the relationships are added. 

in that, it shows all the relationships correctly.

but when it comes to the visual studio it not mapping to the table.


Entity Framework - two connection strings in web.config

$
0
0

Hello everybody,

I have Database in SQL Server, using this for Identity, in my web.config the connection string is like this:

<add name="DefaultConnection" connectionString="Data Source=Max\SQLEXPRESS;Initial Catalog=Advogado;Integrated Security=True" providerName="System.Data.SqlClient" />

After I add some tables for a project in a same Database and by ADO.NET genarated this tables in Models in my project, it made another connection string to my project, in web.config:

<add name="AdvogadoEntities" connectionString="metadata=res://*/Models.AdvogadoDbModel.csdl|res://*/Models.AdvogadoDbModel.ssdl|res://*/Models.AdvogadoDbModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=Max\SQLEXPRESS;initial catalog=Advogado;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

  Questions:

Do I need two connection strings in my web.config for a same database?

If not, how I can join this into unique connection string?

Do i gonna have a problem in deployment of my application to the server with two connection strings?

What is the best practice to deal with connection strings in this contest Database first?

Thank you :)

Appropriate Way of Creating a SQL View In ASP Core Code First Approach

$
0
0

Hi

Googling around led me to deduce that one following the Code First approach can't have a view created for database in the SQL and a model based on the same for an MVC view. The only method I came across was to create a model referring to a similar structured table and having a SQL view with the same structure be created replacing the table so created. In regard of using Code First approach to get an Entity Framework mapped to a view, instead of a table, when an initial migration file was generated, I commented out the portion referring to the said imaginary table, and right at the same position inserted the query as follows:

//Table Part Commented Out
/*migrationBuilder.CreateTable(
    name: "D_XYZ",
    columns: table => new
    {
        ...
    },
    constraints: table =>
    {
        ...
    });*/

//SQL For View Inserted
migrationBuilder.Sql("CREATE VIEW [dbo].[D_XYZ] AS select ...");

However, I find that if I run the Update-Database the said database creates successfully with the required View instead of a table. However, to check it again, I dropped the said database and this time, when I Run the said ASP Core app by F5, the database initialized by it had a Table instead of a View?

  • Why is it so, while I had commented out the relevant portion in the migration file?
  • Isn't the Migration file used upon the launch? or it is based only on the Models as defined?
  • Upon completion of a project and at the time of the deployment, would a manual separate running of the Migration or a Query to drop a Table and replacing it with a View would be required?

Thanks

Unable to determine the relationship represented by navigation property

$
0
0

Hello everyone!

I got this problem trying to migrate 

Unable to determine the relationship represented by navigation property 'ResearcherCourse.ResearcherHumancapitalDoctorateCourse' of type 'ICollection<ResearcherHumancapital>'. Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

this is my class ResearcherCourse

using System;
using System.Collections.Generic;

namespace CadBanco.Models
{
public partial class ResearcherCourse
{
public ResearcherCourse()
{
ResearcherHumancapitalDoctorateCourse = new HashSet<ResearcherHumancapital>();
ResearcherHumancapitalGraduationCourse = new HashSet<ResearcherHumancapital>();
ResearcherHumancapitalMscCourse = new HashSet<ResearcherHumancapital>();
ResearcherInstitutionCourses = new HashSet<ResearcherInstitutionCourses>();
}

public int Id { get; set; }
public string Description { get; set; }
public int? Capes { get; set; }
public DateTimeOffset? Created { get; set; }

public ICollection<ResearcherHumancapital> ResearcherHumancapitalDoctorateCourse { get; set; }
public ICollection<ResearcherHumancapital> ResearcherHumancapitalGraduationCourse { get; set; }
public ICollection<ResearcherHumancapital> ResearcherHumancapitalMscCourse { get; set; }
public ICollection<ResearcherInstitutionCourses> ResearcherInstitutionCourses { get; set; }
}
}

ResearcherHumancapital

using System;
using System.Collections.Generic;

namespace CadBanco.Models
{
public partial class ResearcherHumancapital
{
public ResearcherHumancapital()
{
ResearcherBookResearcher = new HashSet<ResearcherBookResearcher>();
ResearcherHumancapitalArticles = new HashSet<ResearcherHumancapitalArticles>();
ResearcherHumancapitalDoctorateAreas = new HashSet<ResearcherHumancapitalDoctorateAreas>();
ResearcherHumancapitalDoctorateKeywords = new HashSet<ResearcherHumancapitalDoctorateKeywords>();
ResearcherHumancapitalExperience = new HashSet<ResearcherHumancapitalExperience>();
ResearcherHumancapitalGraduationAreas = new HashSet<ResearcherHumancapitalGraduationAreas>();
ResearcherHumancapitalGraduationKeywords = new HashSet<ResearcherHumancapitalGraduationKeywords>();
ResearcherHumancapitalIsoCertification = new HashSet<ResearcherHumancapitalIsoCertification>();
ResearcherHumancapitalKnowledgeAreas = new HashSet<ResearcherHumancapitalKnowledgeAreas>();
ResearcherHumancapitalMscAreas = new HashSet<ResearcherHumancapitalMscAreas>();
ResearcherHumancapitalMscKeywords = new HashSet<ResearcherHumancapitalMscKeywords>();
ResearcherHumancapitalOtherCertification = new HashSet<ResearcherHumancapitalOtherCertification>();
ResearcherHumancapitalResearchLines = new HashSet<ResearcherHumancapitalResearchLines>();
ResearcherHumancapitalThematicNetwork = new HashSet<ResearcherHumancapitalThematicNetwork>();
ResearcherQualiarticleResearcher = new HashSet<ResearcherQualiarticleResearcher>();
ResearcherWorkResearcher = new HashSet<ResearcherWorkResearcher>();
SharedResearcherUbc = new HashSet<SharedResearcherUbc>();
UbcAwardResearcher = new HashSet<UbcAwardResearcher>();
UbcBibliograde = new HashSet<UbcBibliograde>();
UbcBrandResearcher = new HashSet<UbcBrandResearcher>();
UbcExecutiongrade = new HashSet<UbcExecutiongrade>();
UbcInovationgrade = new HashSet<UbcInovationgrade>();
UbcIntelectualgrade = new HashSet<UbcIntelectualgrade>();
UbcOportunityresponsiblemember = new HashSet<UbcOportunityresponsiblemember>();
UbcOrganizationchangeResearcher = new HashSet<UbcOrganizationchangeResearcher>();
UbcPatentResearcher = new HashSet<UbcPatentResearcher>();
UbcProccessResearcher = new HashSet<UbcProccessResearcher>();
UbcProductResearcher = new HashSet<UbcProductResearcher>();
UbcProfessionalgrade = new HashSet<UbcProfessionalgrade>();
UbcProjectResearcher = new HashSet<UbcProjectResearcher>();
UbcProjectfeedback = new HashSet<UbcProjectfeedback>();
UbcSoftwareResearcher = new HashSet<UbcSoftwareResearcher>();
UbcTechnologicaltransferResearcher = new HashSet<UbcTechnologicaltransferResearcher>();
}

public int Id { get; set; }
public string Status { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public string Cpf { get; set; }
public string Phone { get; set; }
public int? GraduationStart { get; set; }
public int? GraduationConclusion { get; set; }
public int? MscStart { get; set; }
public int? MscConclusion { get; set; }
public string MscAdvisor { get; set; }
public string MscThesis { get; set; }
public string MscSector { get; set; }
public int? DoctorateStart { get; set; }
public int? DoctorateConclusion { get; set; }
public string DoctorateAdvisor { get; set; }
public string DoctorateThesis { get; set; }
public string DoctorateSector { get; set; }
public string EmploymentBond { get; set; }
public int? BondTime { get; set; }
public double? ProfessionalLevel { get; set; }
public double? ExecutionGradePedProjectTime { get; set; }
public double? ExecutionGradeGasFinishedProjects { get; set; }
public double? ExecutionGradePedFinishedProjects { get; set; }
public double? ExecutionGradePedIctProjects { get; set; }
public double? ExecutionGradePedFinishedBusiness { get; set; }
public double? InovationGradeProducts { get; set; }
public double? InovationGradeMetodology { get; set; }
public double? InovationGradeAwards { get; set; }
public double? InovationGradeSoftwares { get; set; }
public double? IntelectualGradePatentsDep { get; set; }
public double? IntelectualGradePatentsLic { get; set; }
public double? IntelectualGradeSoftwaresReg { get; set; }
public double? IntelectualGradeTechtransf { get; set; }
public double? BiblioGradeArticlesQuali { get; set; }
public double? BiblioGradeArticlesAnais { get; set; }
public double? BiblioGradeBooks { get; set; }
public double? BiblioGradeAwards { get; set; }
public string XmlPath { get; set; }
public int? DoctorateCourseId { get; set; }
public int? DoctorateInstitutionId { get; set; }
public int? GraduationCourseId { get; set; }
public int? GraduationInstitutionId { get; set; }
public int? JobId { get; set; }
public int? MscCourseId { get; set; }
public int? MscInstitutionId { get; set; }
public int? UserId { get; set; }
public DateTimeOffset? Created { get; set; }

public ResearcherCourse DoctorateCourse { get; set; }
public ResearcherInstitution DoctorateInstitution { get; set; }
public ResearcherCourse GraduationCourse { get; set; }
public ResearcherInstitution GraduationInstitution { get; set; }
public ResearcherJob Job { get; set; }
public ResearcherCourse MscCourse { get; set; }
public ResearcherInstitution MscInstitution { get; set; }
public ICollection<ResearcherBookResearcher> ResearcherBookResearcher { get; set; }
public ICollection<ResearcherHumancapitalArticles> ResearcherHumancapitalArticles { get; set; }
public ICollection<ResearcherHumancapitalDoctorateAreas> ResearcherHumancapitalDoctorateAreas { get; set; }
public ICollection<ResearcherHumancapitalDoctorateKeywords> ResearcherHumancapitalDoctorateKeywords { get; set; }
public ICollection<ResearcherHumancapitalExperience> ResearcherHumancapitalExperience { get; set; }
public ICollection<ResearcherHumancapitalGraduationAreas> ResearcherHumancapitalGraduationAreas { get; set; }
public ICollection<ResearcherHumancapitalGraduationKeywords> ResearcherHumancapitalGraduationKeywords { get; set; }
public ICollection<ResearcherHumancapitalIsoCertification> ResearcherHumancapitalIsoCertification { get; set; }
public ICollection<ResearcherHumancapitalKnowledgeAreas> ResearcherHumancapitalKnowledgeAreas { get; set; }
public ICollection<ResearcherHumancapitalMscAreas> ResearcherHumancapitalMscAreas { get; set; }
public ICollection<ResearcherHumancapitalMscKeywords> ResearcherHumancapitalMscKeywords { get; set; }
public ICollection<ResearcherHumancapitalOtherCertification> ResearcherHumancapitalOtherCertification { get; set; }
public ICollection<ResearcherHumancapitalResearchLines> ResearcherHumancapitalResearchLines { get; set; }
public ICollection<ResearcherHumancapitalThematicNetwork> ResearcherHumancapitalThematicNetwork { get; set; }
public ICollection<ResearcherQualiarticleResearcher> ResearcherQualiarticleResearcher { get; set; }
public ICollection<ResearcherWorkResearcher> ResearcherWorkResearcher { get; set; }
public ICollection<SharedResearcherUbc> SharedResearcherUbc { get; set; }
public ICollection<UbcAwardResearcher> UbcAwardResearcher { get; set; }
public ICollection<UbcBibliograde> UbcBibliograde { get; set; }
public ICollection<UbcBrandResearcher> UbcBrandResearcher { get; set; }
public ICollection<UbcExecutiongrade> UbcExecutiongrade { get; set; }
public ICollection<UbcInovationgrade> UbcInovationgrade { get; set; }
public ICollection<UbcIntelectualgrade> UbcIntelectualgrade { get; set; }
public ICollection<UbcOportunityresponsiblemember> UbcOportunityresponsiblemember { get; set; }
public ICollection<UbcOrganizationchangeResearcher> UbcOrganizationchangeResearcher { get; set; }
public ICollection<UbcPatentResearcher> UbcPatentResearcher { get; set; }
public ICollection<UbcProccessResearcher> UbcProccessResearcher { get; set; }
public ICollection<UbcProductResearcher> UbcProductResearcher { get; set; }
public ICollection<UbcProfessionalgrade> UbcProfessionalgrade { get; set; }
public ICollection<UbcProjectResearcher> UbcProjectResearcher { get; set; }
public ICollection<UbcProjectfeedback> UbcProjectfeedback { get; set; }
public ICollection<UbcSoftwareResearcher> UbcSoftwareResearcher { get; set; }
public ICollection<UbcTechnologicaltransferResearcher> UbcTechnologicaltransferResearcher { get; set; }
}
}

Insert data using EF6 into SQL2016 table with Always Encrypted columns

$
0
0

I've been experimenting with the Always Encrypted feature of SQL 2016 and I have been successful in inserting data into a simple table with encrypted columns so long as I explicitly write a parameterised query.

However if I try and insert the same data using an EF6 object automatically generated from the database I always get errors.

System.Data.Entity.Core.UpdateException: An error occurred while updating the entries. See the inner exception for details. ---> System.Data.SqlClient.SqlException: Operand type clash: nvarchar(max) is incompatible with nvarchar(max) encrypted with (encryption_type = 'DETERMINISTIC', encryption_algorithm_name = 'AEAD_AES_256_CBC_HMAC_SHA_256', column_encryption_key_name = 'CEK1', column_encryption_key_database_name = 'DatabaseName') Incorrect parameter encryption metadata was received from the client. 

It was my understanding that EF used parameterised queries under the hood so what do I need to configure to get this to work? Following another forum post I have tried setting all columns in the database to nvarchar(max) incase EF is setting the data types to the max length by default. I have tried using DataAnnotations to set the datatype and length although I have struggled to find examples of how to do this in VB. I still get variations on the error above, seemingly to do with nvarchar length.

I'm doing this in VB in a .net 4.6 web forms project, Database First approach. At the moment both the SQL instance and the IIS instance are both on my machine.  It isn't compulsory for me to achieve this in EF, I'd just like to know if it can be done. Any advice? Thanks in advance!

How do I work with an integer value read from a SqlDataReader object?

$
0
0

Hello,

I have a SqlDataReader object:

SqlDataReaderEx sdrEx = new SqlDataReaderEx(mConnectionString);

and I created a query string, and it is able to read in string values fine from a SQL database, and I can assign those values fine to string variables.  For example, I can take a "firstname" column field (which is varchar datatype), and assign it to a string variable like below:

string mStudentFirst;
mStudentFirst = sdrEx.String("firstname");

However, if I try and work with a smallint value from a SQL database, I cannot get it to work.  In the below code, the "Typeclass" column of the SQL database is a "smallint" data type:

int mTypeclass;
mTypeclass = Int32.Parse(sdrEx.String("Typeclass"));

I've looked at the available methods of the sdrEx (Sql datareader) object in visual studio, and I don't see anything else that could help me.  I tried using "long" and "toString", but those give immediate errors even before attempting to run the code.  The"sdrEx.String" code I have above does not throw any immediate errors before I run it, but upon actual running, I get this error in my web browser (only partial error is shown below):

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +14198648
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +177

Why does the above code with the Typeclass variable not work?   sdrEx.String should be taking in the column as a string, and then I try to parse that string into an Int32, and assign it to the mTypeclass integer variable.  What's the issue here?  Potentially, it could be that sdrEx.String may be expecting only varchar/char type column data, but I don't see any other SqlDataReader methods that I could use instead.

Can someone please assist me in correcting my problematic code?

Thanks!

Custom Fields with Entity Framework at RunTime

$
0
0

I want to be able to give my user the ability to add custom fields at runtime to a Entity say

Table 1 

Field 1 Field 2 Field 3 CustomField4 add ed at runtime.

I am using Entity Framework and was wondering what is the best practise for this using entity framework and sql server is their any nugets that help with this.

How do I fix this error: ExecuteNonQuery: CommandText property has not been initialized

$
0
0

How do I fix this error: ExecuteNonQuery: CommandText property has not been initialized?

System.Data.SqlClient.SqlCommand.ValidateCommand(bool async, string method)
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource<object> completion, bool sendToPipe, int timeout, bool asyncWrite, string methodName)
System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
NextGenerationUI.Services.PersonActivityLogService.InsertPersonActivityLog(int logId, string edi, string titleOrRank, string firstName, string middleInitial, string lastName, string activityDateTime, string activityTypeDefinition, string additionalDetails, string reasonMessage, string notes) in PersonActivityLogService.cs+
                cmd.ExecuteNonQuery();
NextGenerationUI.Controllers.AccountController+<LoginAsync>d__13.MoveNext() in AccountController.cs+
                _personActivityLogService.InsertPersonActivityLog(0, "edi", "title", "fn", "mi", "ln", "time", "none", "none", "none", "none");

My code:

public void InsertPersonActivityLog(int logId, string edi, string titleOrRank, string firstName, string middleInitial, string lastName, string activityDateTime, string activityTypeDefinition, string additionalDetails, string reasonMessage, string notes)
        {
            StringBuilder errorMessages = new StringBuilder();
            try
            {
                // Get the connection string from the appsettings.json.
                conn.ConnectionString = myConn.DefaultConnectionString(configuration);  //@"Server=BRENTHUMBERDEVE;Database=NextGeneration;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
                                                                                        // Open the connection.
                conn.Open();
                cmd.Connection = conn;

                // Set the command type of the command object.
                cmd.CommandType = System.Data.CommandType.StoredProcedure;

                // Assign values as "parameters to avoid 'SQL Injections.'"
                cmd.Parameters.AddWithValue("@edi", edi);
                cmd.Parameters.AddWithValue("@lName", lastName);
                cmd.Parameters.AddWithValue("@fname", firstName);
                cmd.Parameters.AddWithValue("@mi", middleInitial);
                cmd.Parameters.AddWithValue("@date", activityDateTime);
                cmd.Parameters.AddWithValue("@descriptor", activityTypeDefinition);
                cmd.Parameters.AddWithValue("@details", additionalDetails);
                cmd.Parameters.AddWithValue("@reason", reasonMessage);
                cmd.Parameters.AddWithValue("@notes", notes);
                cmd.ExecuteNonQuery();
            }
            catch(SqlException ex)
            {
                for (int i = 0; i < ex.Errors.Count; i++)
                {
                    errorMessages.Append("Index #" + i + "\n" +"Message: " + ex.Errors[i].Message + "\n" +"LineNumber: " + ex.Errors[i].LineNumber + "\n" +"Source: " + ex.Errors[i].Source + "\n" +"Procedure: " + ex.Errors[i].Procedure + "\n");
                }
                Console.WriteLine(errorMessages.ToString());
            }
            finally
            {
                conn.Close();
                conn.Dispose();
            }
        }


a quick linq to sql question about takewhile and skipwhile

$
0
0

hi

I am doing a number of stock calculations in a basic form I will need to do something like 3 calcualtions on a list of stockrecords to get the records i need.

now from my understanding to use takewhile and skipwhile, i can't use linq to sql, and I would have to call all the records then run a linq statement with takewhile  and skipwhile.

So my question is, is there a way to perform this within at database level, or is this not possible, and if it is possible which is the more recommended way?

Make a chart by date and value from database

$
0
0

Good morning, I need to convert this sql query into a linQ query to populate a chart, I need this char by date and value, to can see the behavior by date. Thanks in advance.

SELECT tb_color.color_value, tb_color.date
FROM tb_color
GROUP BY tb_color.color_value, tb_color.date 
ORDER BY tb_color.date ASC

select 10 rows from sql database at a time, when button is clicked

$
0
0

Hello

So I am working on a project, and when the button is clicked I want to select the first 10 rows from a database, and when clicked again it selects the next 10 rows, and the next and so on.  What I am working on is something of along the lines as a user blog, where that the user can click on the comments, and the first 10 comments are visible, and then they have the ability to click on view more comments, which will then display the next 10 comments.  it allows 10 comments at a time.

Here is a look at my code, and if more code is needed just let me know, but this is where a lot of the action is.

Thanks and I appreciate any help

protected void ViewMoreComments_Click(object sender, EventArgs e)
{
LinkButton MoreComments = sender as LinkButton;
string UserName = Session["UserName"].ToString();
string Id = MoreComments.ID.Remove(0, 16);

//ViewMoreComments[Convert.ToInt32(Id)].Visible = false;
//CommentBox[Convert.ToInt32(Id)].Visible = false;
//PostComment[Convert.ToInt32(Id)].Visible = false;

BlogPost.RetrieveComments(UserName, UserPosts, Id, Text, UserComments,
CommentImage, CommentName, CommentDate, NumOfComments, ViewMoreComments);
}

public void RetrieveComments(string UserName, Panel UserPosts, string Comment, Label[] Text,
Label[,] UserComments, ImageButton[,] CommentImage,
Label[,] CommentName, Label[,] CommentDate,
LinkButton[] NumOfComments, LinkButton[] ViewMoreComments)
{
SqlCommand UpdateComments = new SqlCommand(@"Select Comments, UserName, Date FROM BlogComments WHERE UserPost=@UserPost", connection);

UpdateComments.Parameters.AddWithValue("@UserPost", Text[Convert.ToInt32(Comment)].Text);
UpdateComments.Parameters.AddWithValue("@UserName", UserName);

//int PostNumber = Convert.ToInt32(Comment[c].ID.Remove(0, 7));

//UpdateComments.Parameters["@PostNumber"].Value = Comment;

//int Post = Convert.ToInt32(UpdateComments.ExecuteScalar());

SqlDataAdapter adapter = new SqlDataAdapter(UpdateComments);
DataTable dt = new DataTable();
adapter.Fill(dt);

try
{
for (int c = 0; c < 10; c++)
{
CommentImage[Convert.ToInt32(Comment), c].AlternateText = dt.Rows[c]["UserName"].ToString();
CommentImage[Convert.ToInt32(Comment), c].ToolTip = dt.Rows[c]["UserName"].ToString();
CommentName[Convert.ToInt32(Comment), c].Text = dt.Rows[c]["UserName"].ToString();
CommentDate[Convert.ToInt32(Comment), c].Text = dt.Rows[c]["Date"].ToString();
UserComments[Convert.ToInt32(Comment), c].Text = dt.Rows[c]["Comments"].ToString();

if (UserComments[Convert.ToInt32(Comment), c].Visible == false)
{
UserComments[Convert.ToInt32(Comment), c].Visible = true;
CommentImage[Convert.ToInt32(Comment),c].Visible = true;
CommentName[Convert.ToInt32(Comment), c].Visible = true;
CommentDate[Convert.ToInt32(Comment), c].Visible = true;


if (c == 0)
{
c = 1;
NumOfComments[Convert.ToInt32(Comment)].Text = c + " Comment";
c = 0;
}
else if (c == 1)
{
c = 2;
NumOfComments[Convert.ToInt32(Comment)].Text = c + " Comments";
c = 1;
}
else
{
c = c + 1;
NumOfComments[Convert.ToInt32(Comment)].Text = c + " Comments";
c = c - 1;
}

if(c == 9)
{
ViewMoreComments[Convert.ToInt32(Comment)].Visible = true;
}
else
{
ViewMoreComments[Convert.ToInt32(Comment)].Visible = false;
}
}
else
{
UserComments[Convert.ToInt32(Comment), c].Visible = false;
CommentImage[Convert.ToInt32(Comment),c].Visible = false;
CommentName[Convert.ToInt32(Comment), c].Visible = false;
CommentDate[Convert.ToInt32(Comment), c].Visible = false;
}

}
}
catch
{
connection.Close();
return;

}
connection.Close();
}

LINQ to group by column value

$
0
0

Hi,

I have a table in the following format

ShortName    ActionName

ABC                 Name1

XYZ                  Name1

ABC                  Name2

EFG                    Name2

XYZ                     Name3

ABC                  Name2

This is an audit table which stored the details (shortName ,ActionName and date ) when each time any of the action is performed by the App. There will be only 3 types of action Name.

I need to display a report from this table as follows. that is ,the  count of each action performed by each shortname.

ShortName     Name1     Name2     Name3

ABC                     1               2            0

XYZ                     1                 0          1

EFG                     0                1            1

How can I write the lambda expression to get this result.

How to make anonymous type linq query custom model binding

$
0
0

Hi. I want bind my cutom model (DenetlenenViewModel) but "Yil" property is List. How to bind model linq query?

My Custom Model

public class DenetlenenViewModel
    {
        public int Id { get; set; }
        public string FirmaAdi { get; set; }
        public List<int> Yil { get; set; }
    }

My  Method

public IEnumerable<DenetlenenViewModel> YillarlaBirlikteGetir()
        {
            var firmalar = (from t in FASDBContext.Teklif
                            join d in FASDBContext.Denetlenen
                            on t.DenetlenenId.Value equals d.Id
                            select new DenetlenenViewModel
                            {
                                Id = d.Id,
                                FirmaAdi = d.FirmaAdi,
                                Yil = List<t.Yil> // Error : 'List<t.Yil>' is a type, which is not valid in the given context 
                            }).ToList();
            return firmalar;
        }

Viewing all 1698 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>