ASPForums.Net RSS Feed additions to the content that appears on ASPForums.Net(c) 2019 All rights reserved.Write JOIN Queries using LINQ to SQL and Entity Framework in C# and VB.Net<p>Hello Everybody,</p> <p>I am having problems in joining tables using entity framework&nbsp;&nbsp;6.1.3</p> <p>help me by giving example with it is description and it syntax&nbsp;</p> <p>Suppose I want to Write the following queires using entityframework</p> <p><strong>INNER JOIN</strong></p> <p>SELECT Orders.OrderID, Customers.CustomerName<br />FROM Orders<br />INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;</p> <p><strong>LEFT JOIN</strong></p> <p>SELECT Customers.CustomerName, Orders.OrderID<br />FROM Customers<br />LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID<br />ORDER BY Customers.CustomerName;</p> <p><strong>RIGHT JOIN</strong></p> <p>SELECT Orders.OrderID, Employees.LastName, Employees.FirstName<br />FROM Orders<br />RIGHT JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID<br />ORDER BY Orders.OrderID;</p> <p><strong>FULL OUTER JOIN</strong></p> <p>SELECT Customers.CustomerName, Orders.OrderID<br />FROM Customers<br />FULL OUTER JOIN Orders ON Customers.CustomerID=Orders.CustomerID<br />ORDER BY Customers.CustomerName;</p> <p><strong>SELF JOIN</strong></p> <p>SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City<br />FROM Customers A, Customers B<br />WHERE A.CustomerID &lt;&gt; B.CustomerID<br />AND A.City = B.City&nbsp;<br />ORDER BY A.City;</p> <p>thanks&nbsp;</p>, 15 Jan 2018 00:37:39 GMTWhich is best to use in ASP.Net MVC ADO.Net or Entity Framework<p>Hi...</p> <p>i want fatch data from ERP database ,its having all lots stored procedure ,i want fatch data in MVC Application which database connectitvity&nbsp; is best ADO.NET OR Entity framework ???.</p> <p>&nbsp;</p> <p>Please provide your commands...</p> <p>&nbsp;</p> <p>Thanks &amp; Regards,</p> <p>VENKAT</p> <p>&nbsp;</p> <p>&nbsp;</p>, 17 Aug 2018 09:13:45 GMTUsing Group By clause with Entity Framework in C# .Net<p>i have a scenario where i have to display the state name and number of cities in that state in autocompletet text how to do that</p> <p>&nbsp;</p> <pre class="brush: csharp">[HttpPost] public JsonResult find(string Text) { var suggestedUsers = (from x in lw.RWW_CountriesMaster where x.Country.StartsWith(Text) select new { country = x.Country, capital = x.Capital }).Distinct(); var count = (from x in lw.RWW_CountriesMaster where x.Country.StartsWith(Text) select new { country = x.Country, capital = x.Capital }).Count(); var result = suggestedUsers.Take(5).ToList(); //return result; return Json(result, JsonRequestBehavior.AllowGet); }</pre> <p>&nbsp;</p>, 17 Sep 2014 02:36:28 GMTUse Stored Procedure with Entity Framework in ASP.Net<p>hi</p> <p>how witre procuder or function in Entity framwork.</p> <p>please attend&nbsp; me i want create or write in Designing&nbsp; ef</p> <p>i dont want add from db sql</p> <p>&nbsp;</p> <p>&nbsp;</p>, 13 Mar 2013 00:34:27 GMTUsing Stored Procedure with Entity Framework in Linq query in ASP.Net<p>hi,</p> <p>I am trying to pass parameter to sp in an MVC controller.</p> <p>The stored procedure has a parameter that return a table from a string like 's1,s2,s3' (i have a Split Function in database).</p> <p>In Sql works fine but in my project i get model with no entities</p> <p>when i select the checkboxes that represent the multifilter i have no result</p> <p>I create a comma separated string when user checks the checkboxes that represent the product lines and then i use that string as parameter in stored procedure.</p> <p>i have a sp that works like</p> <pre class="brush: sql">select * from tab where produtLine In (select value from dbo.Split(COALESCE(@Linea,&#34;xxxx&#34;, &#34;,&#34;)...etc</pre> <p>the code in c# works but when i try to pass as Line Line1,Line2..etc I recive no result</p> <p>the code</p> <pre class="brush: csharp"> public ActionResult Index(String cliente, int ? anno, String [] linea, String tipoDati ) { String Codage = &#34;000&#34;; tipoDati = &#34;Ordini&#34;; string lineeSelezionate = null; cliente = cliente == &#34;cliente&#34; ? null : cliente; if (linea != null) { foreach (var item in linea) { lineeSelezionate += item + &#34;,&#34;; } lineeSelezionate = &#34;&#39;&#34; + lineeSelezionate.Substring(0, lineeSelezionate.Length - 1) + &#34;&#39;&#34;; } IEnumerable&lt;OrdineMeseLineaView&gt; model; if (string.IsNullOrEmpty(cliente) &amp;&amp; anno == null &amp;&amp; linea == null) { model = new List&lt;OrdineMeseLineaView&gt; { new OrdineMeseLineaView { Linea = &#34;&#34;, Gen = 0, Feb = 0, Mar = 0, Apr = 0, Mag = 0, Giu = 0, Lug = 0, Ago = 0, Set = 0, Ott = 0, Nov = 0, Dic = 0,Tot=0} }; } else { model = db.Database. SqlQuery&lt;OrdineMeseLineaView&gt;(&#34;dbo.PivotOrdiniMeseLineaSp @p0, @p1,@p2, @p3&#34;, Codage, (object)cliente ?? DBNull.Value, (object)anno ?? DBNull.Value, (object)lineeSelezionate ?? DBNull.Value).ToList(); } return View(model); }</pre>, 13 Nov 2017 06:44:51 GMTUsing Stored Procedure with Entity Framework in ASP.Net MVC<p>How to use a stored procedure in MVC project with Entity framework</p> <p>&nbsp;</p> <p>Thanks</p> <p>R</p>, 27 Nov 2018 05:45:39 GMTUsing reflection to loop through related tables in entity object in ASP.Net<p>Hi there&nbsp;</p> <p>&nbsp;</p> <p>I need some help how do i&nbsp;using reflection to loop through related tables in entity object. so that i can find if and entitiy object is been used in any of the other tables</p>, 24 Jun 2016 02:25:03 GMTUsing Lambda expression instead of For Each Loop in ASP.Net<p>I have used for each loop and counter, I got code review comment like "please use a lamba expression here, to isolate an occurrence, as opposed to iterating over all and then doing something in response to all found "</p> <p>Please help how to use lamda expresion here. Thanks.</p> <pre class="brush: vb">Private Function DiamondScoreCheckForOdType(ByVal currentPolicyLob As String, ByVal predominantState As String, ByVal policyEffectiveDate As Date) As Boolean Dim listOfLobForDiamondScoreRule As New HashSet(Of String) From {{getLineOfBusiness(Lob.LineOfBusiness.Auto)}, {getLineOfBusiness(AutoNonDealer)}, {getLineOfBusiness(Lob.LineOfBusiness.Garage)}, {getLineOfBusiness(EmploymentPracticesLiability_EP)}, {getLineOfBusiness(GeneralLiability)}, {getLineOfBusiness(InlandMarine)}, {getLineOfBusiness(PesticideHerbicide)}, {getLineOfBusiness([Property])}, {getLineOfBusiness(Umbrella)}} Dim lobList As New List(Of String) Dim eligibleLobCheckCounter As Integer = 0 lobList = currentPolicyLob.Split(ASTERISK).ToList() For Each currentLob In lobList listOfLobForDiamondScoreRule.Contains(currentLob) If (listOfLobForDiamondScoreRule.Contains(currentLob)) Then eligibleLobCheckCounter = eligibleLobCheckCounter + 1 End If Next If (eligibleLobCheckCounter &gt; 0) Then Dim isStateAndEffDateEligible As Boolean = (New LobCO.Shared.COShared).IsStateRuleApplicable(getLineOfBusiness(Lob.LineOfBusiness.Common), predominantState, policyEffectiveDate, DiamondScoreRuleCheckForOdType) Return isStateAndEffDateEligible End If Return False End Function</pre> <p>&nbsp;</p>, 07 Sep 2018 01:52:46 GMTRead SQL Server table and write to SQLite using Entity Framework in ASP.Net<p>Hi,</p> <p>i have to&nbsp; create an application for sales force to collect orders.</p> <p>I need some tables of company (customers, products...ecc).</p> <p>I need to read the tables above from sql server database and write to SQLite database.</p> <p>How can i solve this task? I never do that.</p> <p>I would use&nbsp; simple form application wit Entity Framework to serialize and write.</p> <p>I need some sample to start (video,link...)</p> <p>tks to everybody</p>, 08 Oct 2018 00:26:09 GMTPopulate Windows Forms ComboBox control using Entity Framework<p>HI,<br /> &nbsp;<br /> I tried to show list of name on cmbobox<br /> &nbsp;<br /> <br /> this is the code(query<br /> var query = (from p in dbhome.Stores select new { p.FNameware, }).ToList();<br /> Cbox.DataSource = query.ToList();</p>, 09 Mar 2013 07:21:53 GMTUse Output Parameter with Entity Framework (Edmx) in C# .Net<p>I have develop a function to add textbox value into data base my function work perfectly .now I am using that table primary key into another table where it declare as a foreign key now i required to return my Id as a output parameter in table1 &nbsp;means( set scope identity) &nbsp;&nbsp;&nbsp;so that I used this Id into another table as a foreign key please help me how I used this scope identity into a web method</p> <pre class="brush: js">function Insertdata() { var name = $(&#39;#txtfname&#39;).val(); $.ajax({ type: &#39;POST&#39;, url: &#34;Insert.aspx/DataInsertion&#34;, contentType: &#34;application/json; charset=utf-8&#34;, data: &#39;{name:&#34;&#39; + name + &#39;&#34;, Id:&#34;&#39; + output + &#39;&#34;}&#39;, async: false, success: function (response) { alert(&#34; Saving the Data.!&#34;); }, error: function () { alert(&#34;Some Error occured While Saving the Data.!&#34;); } }); }; </pre> <p>&nbsp;</p> <pre class="brush: csharp">Web method [WebMethod] public static string DataInsertion(string name Id output) { using (var db = new MyEntities())///////this is edmx name { db.Insertion( Name=name, Id=Output ); } return &#34; Data Successfully Saved&#34;; } </pre> <p>I read a lot of article but I have no idea to use it.</p> <p>Please help me&nbsp;</p>, 07 Aug 2015 09:26:31 GMTUnable to add Namespace using Entity Framework in ASP.Net<p>I'm follow your code(<a href="">code link</a>) from here. but I don't understand where I use AddToCustomers Method and I'm unable to Add NameSpace "TestModelNs".<br />Here is my aspx file(<a href="">files link</a>)</p>, 03 Dec 2017 01:05:54 GMTSystem.Data.SqlClient.SqlException: Invalid object name 'Phase1'<p>Hi....,</p> <p>I got an error of&nbsp;System.Data.SqlClient.SqlException: Invalid object name 'Phase1'like this but in my code there is no Phase1..what should i do..plz help me...</p>, 16 Sep 2014 10:04:10 GMTSum of DataTable columns total using Lambda Expression in Entity FrameWork in ASP.Net<pre><font color="red"> decimal total = dt.AsEnumerable().Sum(row =&gt; row.Field&lt;decimal&gt;("TotalAmount"));<br /><br /><br /><br />when i try to add the total amount from grid view row then i'm faicing above error sir</font></pre>, 19 Dec 2016 05:15:01 GMTSum of Column using Linq Lambda Expression in ASP.Net<p>how to use &nbsp;this Query in linq Lamda Expression&nbsp;</p> <pre class="brush: sql">Select&nbsp; sum(AmountPaid) as TotalAmountPaid from StudentLedger where FeeTypeID in&nbsp;(1,2) and StudentID =639</pre> <p>&nbsp;</p>, 18 May 2018 01:12:37 GMTSelect specific Columns in Entity Framework using Linq query in ASP.Net<p>&nbsp;</p> <pre class="brush: csharp"> var res = tbb.tbl_Enquiry.Where(x =&gt; x.Enq_broker == enq).ToList();</pre> <p>I Want to get not all column some specific column from tbl_Enquiry&nbsp;</p>, 06 Jul 2018 00:13:52 GMTSelect record having age between 18 and 21 using Linq query in Entity Framework<p>i m finding user according to age, but in database i have only date of birth, my dob in database is date type.stores values like&nbsp;1990-08-22,</p> <p>in need to find users from age 18 to age 25</p>, 07 Aug 2018 00:50:14 GMTSelect record from database with Join and where conditions using Linq query in ASP.Net<p>userlist1 showing all user values, but userlist2 not showing value.</p> <p>Can i apply condition where direct to userlist1 how?</p> <pre class="brush: csharp">string dob2 = dobyear2 + &#34;-&#34; + month + &#34;-&#34; + 1; DateTime dob22 = Convert.ToDateTime(dob2); List&lt;User_Detail&gt; userlist = new List&lt;User_Detail&gt;(); // userlist = db.User_Detail.Where(s =&gt; s.Gender == 2 &amp;&amp; s.DOB &lt;= dob21 &amp;&amp; s.DOB &gt;= dob22).ToList(); var userlist1 = (from u in db.User_Detail &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join st in db.State_Name on u.State equals st.State_Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join h in db.Height_Table on u.Height equals h.Height_Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join e in db.Education_Qualification on u.Education_Qualification equals e.Education_Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join leng in db.Mother_Tongue on u.Mother_Tongue equals leng.Language_id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join rlgn in db.Religions on u.Religion equals rlgn.Religion_Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join cast in db.Castes on u.Caste equals cast.Caste_Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; join incm in db.AnnuaIncome_Table on u.Annual_Income equals incm.Income_Id &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select new users_details &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; First_Name = u.First_Name, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Last_Name = u.Last_Name, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Annual_IncomeName = incm.Annual_Income, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Caste1 = cast.Caste1, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Religion_Name = rlgn.Religion_Name, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Language = leng.Language, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EducationName = e.Education, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; StateName = st.State &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }).ToList(); var userlist2 = userlist1.Where(s =&gt; s.Gender == 2 &amp;&amp; s.DOB &lt;= dob21 &amp;&amp; s.DOB &gt;= dob22).ToList(); </pre> <p>&nbsp;</p> <p>&nbsp;</p>, 10 Aug 2018 06:13:54 GMTSave binary image in Database using Entity Framework in ASP.Net<p>I want to save image into database using entity framework without mvc.</p> <p>I have tried bt it wont worked. Plz Help me out from this problem.</p> <p>Below I have attached file which i have tried</p> <p>.aspx code</p> <pre class="brush: html">&lt;div style=&#34;float:left&#34;&gt; &lt;table&gt; &lt;tr &gt; &lt;td style=&#34;padding-left:5px&#34;&gt; &lt;div style=&#34;float:left&#34;&gt; &lt;asp:Image ID=&#34;Image1&#34; ImageUrl=&#34;http://localhost:9002/Images/pup.jpg&#34; runat=&#34;server&#34; class=&#34;img-circle&#34; /&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;div style=&#34;float:none&#34;&gt; &lt;asp:Label ID=&#34;lblAllow&#34; runat=&#34;server&#34; Text=&#34;Allowed file types: TIF, PNG, JPG&#34; &gt;&lt;/asp:Label&gt;&lt;br /&gt; &lt;asp:FileUpload ID=&#34;FileUpload1&#34; runat=&#34;server&#34; UploadedFilesRendering=&#34;BelowFileInput&#34;/&gt;&lt;br /&gt;&lt;br /&gt; &lt;div style=&#34;text-align:center&#34;&gt; &lt;Telerik:RadButton ID=&#34;RadBtnUpload&#34; runat=&#34;server&#34; Text=&#34;Upload Selected&#34; skin=&#34;Windows7&#34; style=&#34;align-self:center&#34; OnClick=&#34;RadBtnUpload_Click&#34;&gt; &lt;Icon PrimaryIconCssClass=&#34;RadBtnUpload&#34; /&gt; &lt;/Telerik:RadButton&gt; &lt;/div&gt; &lt;asp:RegularExpressionValidator ID=&#34;RegularExpressionValidator3&#34; ValidationExpression=&#34;([a-zA-Z0-9\s_\\.\-:])+(.png|.PNG|.jpg|.JPG|.tif|.TIF)$&#34; ControlToValidate=&#34;FileUpload1&#34; runat=&#34;server&#34; ForeColor=&#34;Red&#34; ErrorMessage=&#34;Only JPG, PNG, TIF allowded.&#34; ShowMessageBox=&#34;true&#34; Display=&#34;Dynamic&#34; /&gt; &lt;/div&gt; &lt;/div&gt;</pre> <p>.asp.cs code</p> <pre class="brush: csharp"> protected void RadBtnUpload_Click(object sender, EventArgs e) { string folderPath = Server.MapPath(&#34;~/Forms/Uploads/&#34;); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName)); Image1.ImageUrl = &#34;~/Forms/Uploads/&#34; + Path.GetFileName(FileUpload1.FileName); EmployeePortal.Models.NCI.NCIEntities ent = EmployeePortal.Models.ClsNCIUtil.GetNCIEntity(Session[&#34;CustomerID&#34;].ToString()); using (ent) { EmployeePortal.Models.NCI.EmployeeImage eimg = ent.EmployeeImages.FirstOrDefault(a =&gt; a.EmployeeId == empno);//&amp;&amp; a.CustomerId == customerId); if (FileUpload1.HasFile) { var img= (from a in ent.EmployeeImages where a.EmployeeId == empno select a.EmpImage); byte[] FileUpload1 = eimg.EmpImage; ent.SaveChanges(); } } </pre> <p>plz help me.... </p> <pre class="brush: sql">CREATE TABLE [dbo].[EmployeeImage]( [SrNo] [int] IDENTITY(1,1) NOT NULL, [EmployeeId] [int] NULL, [CustomerId] [int] NULL, [EmpImage] [image] NULL, [LastModifiedDate] [datetime] NULL, [LastModifiedUser] [nvarchar](25) NULL, [LastModifiedDescription] [varchar](200) NULL, CONSTRAINT [PK_EmployeeImage] PRIMARY KEY CLUSTERED ( [SrNo] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]</pre> <p>&nbsp;</p>, 27 Sep 2018 01:24:30 GMTPM EntityFramework -Version 6.0.0-alpha1 -Pre The term EntityFramework is no<p>hi when install EntityFramework -Version 6.0.0-alpha1 -Pre in</p> <p>&nbsp;</p> <p>i see this error</p> <p>PM&gt; EntityFramework -Version 6.0.0-alpha1 -Pre <br />The term 'EntityFramework' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify<br />&nbsp;that the path is correct and try again.<br />At line:1 char:16<br />+ EntityFramework &lt;&lt;&lt;&lt;&nbsp; -Version 6.0.0-alpha1 -Pre <br />&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : ObjectNotFound: (EntityFramework:String) [], CommandNotFoundException<br />&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : CommandNotFoundException</p> <p>&nbsp;</p> <p>whats problem for me?<br />&nbsp;</p>, 29 Mar 2013 08:48:39 GMTOptional One to Many relationships in Entity Framework<p>Hello every one;</p> <p>can we have optional one to many relationship in entityframework</p> <p>&nbsp;Note: a person can be realate to a department or it might no and a Department can have many person</p> <pre class="brush: csharp">public class Person { public int Id{ get; set; } public Department Department { get; set; } public int DepartmentId } public class Department { public int Id{ get; set; } public List&lt;Person&gt; Members { get; set; } }</pre> <p>Person to Department</p> <pre class="brush: csharp">.HasOptional(m =&gt; m.Department) .WithOptional( d =&gt; d.Members) .HasForeignKey( m=&gt; m.DepartmentId);</pre> <p>&nbsp;For Example</p> <p>Id&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Name&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DepartmentId</p> <p>1&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;John&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x</p> <p>2&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Ahmad&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y</p> <p>3&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Persony&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL</p> <p>4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Personz&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; x</p> <p>thanks</p>, 08 Sep 2018 03:59:06 GMTObject Name dbo.Poste invalid. or Object Name dbo.User invalid in Entity Framework<p>I am developing an ASP .Net MVC 3 application using C# and SQL Server 2005.</p> <p>I've created 2 models (User &amp; Poste) with their controllers (UserController &amp; PosteController) thanks to the method of creation with 'Read/Write actions and views, using Entity Framework'.</p> <p>When i would like to access to the view of User or Poste, that's mean when I put /Poste (or /User) in my URL to access to the index, this error appears to me :</p> <p>&nbsp;</p> <pre class="brush: xml">Object Name &#39;dbo.Poste&#39; invalid. or Object Name &#39;dbo.User&#39; invalid.</pre> <p><span>This is the model of User :</span></p> <p><span><br /></span></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Globalization; using System.Web.Mvc; using System.Web.Security; using System.Data.SqlClient; using System.Data.Entity; namespace MvcApplication2.Models { public class User { [Required] [Key] [Display(Name = &#34;Matricule :&#34;)] public string Matricule { get; set; } [Required] [Display(Name = &#34;Nom :&#34;)] public string Nom_User { get; set; } [Required] [StringLength(100, ErrorMessage = &#34;Le {0} doit avoir au minimum {2} caract&egrave;res.&#34;, MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = &#34;Mot de passe :&#34;)] public string passWord { get; set; } [Required] [Display(Name = &#34;Type :&#34;)] public string Type_User { get; set; } [Required] [Display(Name = &#34;ID_UF :&#34;)] public string ID_UF { get; set; } } }</pre> <p>this is the Controller of User :</p> <div>&nbsp;</div> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Data; using System.Data.Entity; using System.Linq; using System.Web; using System.Web.Mvc; using MvcApplication2.Models; namespace MvcApplication2.Controllers { public class UserController : Controller { private GammeContext db = new GammeContext(); // // GET: /User/ public ViewResult Index() { return View(db.Users.ToList()); } // // GET: /User/Details/5 public ViewResult Details(string id) { User user = db.Users.Find(id); return View(user); } // // GET: /User/Create public ActionResult Create() { return View(); } // // POST: /User/Create [HttpPost] public ActionResult Create(User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return RedirectToAction(&#34;Index&#34;); } return View(user); } // // GET: /User/Edit/5 public ActionResult Edit(string id) { User user = db.Users.Find(id); return View(user); } // // POST: /User/Edit/5 [HttpPost] public ActionResult Edit(User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction(&#34;Index&#34;); } return View(user); } // // GET: /User/Delete/5 public ActionResult Delete(string id) { User user = db.Users.Find(id); return View(user); } // // POST: /User/Delete/5 [HttpPost, ActionName(&#34;Delete&#34;)] public ActionResult DeleteConfirmed(string id) { User user = db.Users.Find(id); db.Users.Remove(user); db.SaveChanges(); return RedirectToAction(&#34;Index&#34;); } protected override void Dispose(bool disposing) { db.Dispose(); base.Dispose(disposing); } } }</pre> <p><span>and this the context Class (GammeContext) :</span></p> <p><span><br /></span></p> <pre class="brush: csharp">using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data.Entity; namespace MvcApplication2.Models { public class GammeContext:DbContext { public DbSet&lt;Poste&gt; Postes { get; set; } public DbSet&lt;User&gt; Users { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Conventions.Remove&lt;System.Data.Entity.ModelConfiguration.Conventions.PluralizingTableNameConvention&gt;(); } } }</pre> <p><span>and this is what I added in my web.config file :</span></p> <p><span><br /></span></p> <pre class="brush: xml">&lt;add name=&#34;GammeContext&#34; connectionString=&#34;Data Source=SWEET-DE396641E\SQLEXPRESS;database=Flux; Integrated Security=true&#34; providerName=&#34;System.Data.SqlClient&#34; /&gt;</pre> <p>&nbsp;</p>, 02 May 2013 02:35:15 GMTNo suitable constructor found for entity type Model. The following parameters could not be bound t<p><strong>My model`</strong></p> <p>&nbsp;</p> <pre class="brush: csharp">public class User : Iuser { [Key] [DatabaseGenerated(DatabaseGeneratedOption.Identity)] public int? Id { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } [NotMapped] public string Password { get; set; } [NotMapped] public string ConfirmPassword { get; set; } public string Hash { get; set; } public string Salt { get; set; } public DateTime? CreatedOn { get; set; } public User(int? id = null, string firstname = null, string lastname = null, string email = null, string password = null, string confirmpassword = null) { this.Id = id; this.FirstName = firstname; this.LastName = lastname; this.Email = email; this.Password = password; this.ConfirmPassword = confirmpassword; } public User(Iuser obj) { this.Id = obj.Id; this.FirstName = obj.FirstName; this.LastName = obj.LastName; this.Email = obj.Email; this.Password = obj.Password; this.ConfirmPassword = obj.ConfirmPassword; } </pre> <p>my Context`</p> <pre class="brush: csharp">public class UserContext : BaseDbContext { public DbSet&lt;User&gt; Users { get; set; } public UserContext() { } public UserContext(DbContextOptions&lt;UserContext&gt; options):base(options) { } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(CL.Config.DbConfig.ConnectionString); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity&lt;User&gt;(u =&gt; { u.HasKey(e =&gt; e.Id); u.Property(e =&gt; e.FirstName); u.Property(e =&gt; e.LastName); u.Property(e =&gt; e.Email); u.Property(e =&gt; e.Password); u.Property(e =&gt; e.ConfirmPassword); u.Property(e =&gt; e.Salt); u.Property(b =&gt; b.Hash); }); } public void AddUser(User entity) { using (UserContext context = new UserContext()) { entity.CreatedOn = DateTime.Now; nfigFile(entity.Password, &#34;MD5&#34;); context.Users.Add(entity); context.SaveChanges(); } } }</pre> <p>(BaseDbContext inherits from DbContext)</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>so this will automatically create table in database with these properties, but it's not working, still same error for suitable constructor!, how can i create that constructor correctly, i am using core2.1</p>, 15 Jan 2019 05:54:08 GMTMultiple Where conditions in Entity Framework C# .Net<p>i want to get one record <br />with multi condition <br />for example username == "me" and age grather than 20<br />please help me</p>, 15 Sep 2014 04:38:51 GMTMove and delete multiple rows in database table using EntityFramework in ASP.Net<p>i have a table members with column age&nbsp;</p> <table width="257"> <tbody> <tr> <td width="64">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="52">age&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="77">&nbsp;dob&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="64">location</td> </tr> <tr> <td>&nbsp;rick&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>19</td> <td>3/3/2001</td> <td>kl</td> </tr> <tr> <td>&nbsp;fred&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>19</td> <td>12/2/2002</td> <td>Gl</td> </tr> <tr> <td>&nbsp;grace&nbsp;&nbsp;</td> <td>18</td> <td>8/1/2001</td> <td>fh</td> </tr> <tr> <td>&nbsp;amos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>17</td> <td>9/3/1999</td> <td>gh</td> </tr> </tbody> </table> <p>using these code am able to increase the ages by 1 with a click Dim db As New DataContext</p> <p>&nbsp;</p> <pre class="brush: vb">Dim db As New DataContext Dim MembersRecords = From p In db.members Select p Dim age As Integer = 0 For j = 1 To MembersRecords.Count() If MembersRecords.ToList(j - 1).age &lt;&gt; &#34;&#34; Then age = Val(MembersRecords.ToList(j - 1).age) Else age = 0 End If age = age + 1 MembersRecords.ToList(j - 1).age = age Next db.SubmitChanges() End Sub</pre> <table width="257"> <tbody> <tr> <td width="64">name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="52">age&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="77">&nbsp;dob&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td width="64">location</td> </tr> <tr> <td>&nbsp;rick&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>20</td> <td>3/3/2001</td> <td>kl</td> </tr> <tr> <td>&nbsp;fred&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>20</td> <td>12/2/2002</td> <td>Gl</td> </tr> <tr> <td>&nbsp;grace&nbsp;&nbsp;</td> <td>19</td> <td>8/1/2001</td> <td>fh</td> </tr> <tr> <td>&nbsp;amos&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td> <td>18</td> <td>9/3/1999</td> <td>gh</td> </tr> </tbody> </table> <p>with the same button click i want to select and move memebers at age 20 to a diffent table called 'old members' and deleting it from the members table</p> <p>any help please</p>, 24 Jul 2018 07:23:28 GMTMove and delete checked rows in database using Entity Framework in ASP.Net<p>Thanks to Pandeyism for helping me we these codes</p> <p></p> <p>But i whant to a a dynamic checkbox to the view and move and delete it based on the checked rows</p> <p>what am i doing wrong here </p> <pre class="brush: vb">Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load If Not IsPostBack Then Me.BindGrid() End If Dim checkBoxColumn As New DataGridViewCheckBoxColumn() checkBoxColumn.HeaderText = &#34;&#34; checkBoxColumn.Width = 30 checkBoxColumn.Name = &#34;check&#34; DataGridView1.Columns.Insert(0, checkBoxColumn) DataGridView1.AllowUserToAddRows = False End Sub Private Sub BindGrid() Dim test As TestEntities = New TestEntities() gvMembsers.DataSource = From m In test.members Select m gvMembsers.DataBind() End Sub Protected Sub btnInsert_Click(ByVal sender As Object, ByVal e As EventArgs) Dim test As TestEntities = New TestEntities() Dim isSelected As Boolean = Convert.ToBoolean(row.Cells(&#34;check&#34;).Value) Dim memberOldRecord = (From o In test.members Where isSelected = True Select o).ToList() If isSelected Then For j As Integer = 0 To memberOldRecord.Count() - 1 Using test1 As TestEntities = New TestEntities() Dim ol As Oldmember = New Oldmember With { .name = memberOldRecord(j).name, .age = memberOldRecord(j).age, .dob = memberOldRecord(j).dob, .location = memberOldRecord(j).location } test1.AddToOldmembers(ol) test1.SaveChanges() End Using Next Me.BindGrid() End if Using test2 As TestEntities = New TestEntities() Dim mem = (From c In test2.members Where c.age &gt;= 20 Select c).ToList() For i As Integer = 0 To mem.Count() - 1 Dim member As member = mem(i) test2.DeleteObject(member) test2.SaveChanges() Next gvOldmembers.DataSource = mem gvOldmembers.DataBind() Me.BindGrid() End Using End Sub</pre> <p>will appriciate if the logics is explain please</p>, 31 Jul 2018 04:22:45 GMTLogging Database Operations using Entity Framework in .Net Core<p>With entity framework 6 just use context.Database.Log</p> <p>but with ef core how can i log sqlite query?</p>, 21 Dec 2018 03:58:20 GMTLinq query to get sum of column using Entity Framework in ASP.Net<p>Hi,</p> <p>I Want To This Sql Query In Entity Framwork&nbsp; </p> <pre class="brush: sql">select sum(LoanValue) from tbLoans where BorrowerID=66</pre>, 23 Jul 2018 03:48:32 GMTJoin multiple Tables using Entity Framework in Linq query using C# in ASP.Net<p>I have 2 tables</p> <p>first is tbl_News and 2nd is tbl_Category.</p> <p>1st tables has ID,Description,Date,Status,City and CategoryID</p> <p>2nd tables has Id,CategoryName. &nbsp; i want to show all columns of news table but i want to show categoryName in place of CategoryID</p> <pre class="brush: csharp">var News = from n in tbl_News join c in tbl_Category on n.CategoryId equals c.CategoryID &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select new { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ID = n.ID, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Description = n.Description, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Date = n.Date, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Status = n.Status, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; City = n.City, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Category = c.CategoryName &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }.ToList();</pre> <p>Here 1 got error tbl_category is type, not a valid in given context.</p> <p>&nbsp;</p>, 13 Feb 2018 23:49:31 GMTInserting into multiple Table using Entity Framework in ASP.Net<p>Hi ,</p> <p>&nbsp;I have a registration page fields are : username , Address , phoneno.</p> <p>i have 3 tables in data base :</p> <p>User : user id primary key , username</p> <p>Address : user id primary key , address&nbsp;</p> <p>Contact : user id , phoneno</p> <p>i am using entity frame work so i got 3class defaultly.</p> <p>now requirement is when i click on register button those fields i have to insert into those &nbsp;3 tables in a proper way</p> <p>Please help regarding this&nbsp;</p>, 29 Feb 2016 06:27:12 GMT