Tag: entity-framework

Issue accessing database on my network (connection timeout)

I have SQL Server 2008 R2 SP2 on my desktop with a database named “DB” on it (SQL Server and Windows authentication mode). I created a login/user to access the database without using the windows authentication (I know, it’s bad, we’ll discuss it after). From my laptop, I have no problem accessing the database in […]

Database design (SQL CE) in Mvc 4 project using Entity Framework Code First – a few questions

In the application I’m developing a user is presented with a number of preferences that they should personalise. The following describes how I think it should be implemented: A preference: public enum Weighting { One, Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten } public class PreferenceOption { public bool PreferenceOptionSelected { get; set; […]

compare databases (tables only) using C# and Ado.net

I am trying to develop a software that takes two databases as its input, compares there tables and show differences between tables. This is what I think and develop. 1) Select all the servers that are installed on machine. 2) Depending on the selected server it list all the databases installed. 3) Depending upon the […]

How to convert byte array (SQL-server Timestamp) to DateTime (C#)?

How can I convert an array of bytes into DateTime? I must do this because I use a property (named CreationDataStamp) with attribute Timestamp for entity framework. A second property (named CreationDate) I use for convert the byte array into DateTime. [System.ComponentModel.DataAnnotations.Timestamp] public byte[] CreationDateStamp { get; set; } [System.ComponentModel.DataAnnotations.Schema.NotMapped] public DateTime CreationDate { get […]

NEWID() SQL Server Function in Entity Framework

I am developing a web application using AngularJS, ASP.NET, Entity Framework and a SQL Server database. I want to insert some rows using EF with this method : public string addRow(int CaptionID, string enLang) { string output = “”; try { var Cap = new Table_Name(); string userName = System.Security.Principal.WindowsIdentity.GetCurrent().Name; Cap.CodeId = CaptionID; Cap.Created = […]

Custom Entity Framework many-to-many navigation property

I have a many-to-many mapping/pivot table I had to expose as an Entity in order to model a relationship similar to the following (as per this question Model Entity Framework many-many plus shared relation): Now, I would like to emulate the EF collection Enumerate/Add/Remove functionality that is present on the navigation property of a ‘stock’ […]

How to avoid plan cache bloat using queries in entity framework

I found a related question about entity framework here – Why is Entity Framework passing a parameter as DECIMAL(5,0) for a column defined with NUMERIC(19)? – however the answer explains this as regular behavior of entity framework. In a LinqToEntities query, such as this one: var query = (from x in ctx.bigProduct.AsNoTracking() where x.ListPrice == […]

Get Distinct rows according to one column and order by date

I have the following scenario which can solved on the database level or the Linq to EF level: Here is my view in the database: id title date weight ================================== 1 t1 2013-01-18 1.5 1 t1 2013-01-17 1.4 1 t1 2013-01-15 1.31 1 t1 2013-01-12 1.22 2 t2 2013-01-19 2.3 2 t2 2013-01-16 2.1 2 […]

EF6 Does not generate foreign key association from database

PROBLEM: I am trying to create a EF6 model using the database first approach. Simply speaking, I have 2 tables tblUser and tblMilkMan which have a foreign key relationship on the UserID column. But when I create a new EDMX diagram and add the 2 tables: I dont see the relationship No navigation properties are […]

Updating primary key in Entity Framework Code First

I want to update a mediate table’s primary keys. This post suggests to take another primary key and don’t change it, but we’re using our tables in other non-EF projects, I didn’t designed them and I’m not able to change them. Do I have any other option? Anything? Even deleting the old record and inserting […]

MS SQL Server is a Microsoft SQL Database product, include sql server standard, sql server management studio, sql server express and so on.