entity-framework-5

Multiple string connections in EF DbContext

 ̄綄美尐妖づ 提交于 2019-12-12 01:33:13
问题 I’m developing a MVC Website based in codeplex EFMVC solution, and I’m using Entity Framework and Repository, Unit of Work and Command Patterns. My website needs to be a SaaS solution (software as a service) multiple database. In my legacy Asp.Net WebForms I have a XML file that holds all the different string connections and I’m trying to use the same strategy. So in my LoginController I create a command that has company (to identify in which database will be connected) username and password.

Database first generation Entity Framework 5 System.Data.Entity vs EntityFramework

心已入冬 提交于 2019-12-11 23:29:35
问题 Trying to use Visual Studio 2012, Entity Framework 5.0 database first approach to generate my edmx. When I generate the EDMX from the database VS 2012 - says Successfully registered the assembly 'System.Data.Entity, Version=4.0.0.0; web.config file as well says <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral.../> I see EntityFramework and System.Data.Entity both listed in the references. EntityFramework shows up in the packages folder and System.Data.Entity points to the

Unable to cast object of type System.Data.Objects.ObjectStateEntryDbUpdatableDataRecord to ComplexType

跟風遠走 提交于 2019-12-11 20:09:58
问题 I want to get a string value from an ObjectStateEntry and have the following converter. My customer class has an address field which is a complex type. However my code fails to handle this. private static string EntryToString( ObjectStateEntry entry, string fieldName, Context Db) { try { string fieldValue = ""; int ordinal = 0; var createdField = entry.CurrentValues.DataRecordInfo.FieldMetadata.FirstOrDefault(f => f.FieldType.Name == fieldName); var fieldType = createdField.FieldType

Entity Framework 5: DbGeography

大兔子大兔子 提交于 2019-12-11 18:44:01
问题 I'm trying to access the DbGreography datatypes in my solution. I've installed EF5 via nuget. I've referenced System.Data.Entity in which the spatial types are supposed to reside. However, There dont seem to be any system.data.spatial namespace in there. I'm using vs.net 2012 also. What am I missing here? 回答1: The geography types are in System.Data.Entity assembly version 4.0.0.0. If your project was targeting a different framework when you installed EF5, you may well have got a reference to

DBContext Native SQL Queries

一世执手 提交于 2019-12-11 18:32:10
问题 How to use native queries with DBContext ? If I run the code, this give me exception. Why and what to do to run native query when using DBContext ? AcademyEntities context = new AcademyEntities(); string nativeSQLQuery = "SELECT * " + "FROM dbo.Employees " + "WHERE FirstName='{0}'"; string name = "Guy"; var emp = context.Departments.SqlQuery(nativeSQLQuery, name); foreach (var item in emp) { } 回答1: You're querying the Employees table, but trying to materialize Department objects. Change your

Entity Framework lookup table

删除回忆录丶 提交于 2019-12-11 18:30:06
问题 I have 3 tables Brands: BrandID int BrandName varchar(30) Products ProdID int ProdName varchar(30) BrandToProd: BrandID int => FK Brands.BrandID ProdID int => FK Products.ProdID After generating model from existing database EF omits BrandToProd table and creates Many-To-Many relationships between Brands and Products. I would like to have third entity with following fields: BrandName varchar(30) ProductsName varchar(30) This will give me possibility to use scaffolding for this entity. Ideally,

EF 5.0 (Database-First Model) not working on one table

你。 提交于 2019-12-11 18:02:17
问题 I have a database table called TBLFIRM. I am using acc database-first model. EF prepares the sql wrong. What can be wrong on this object? Thank you My Syntax, a very simple call: TBLFIRM d = VT.TBLFIRMs.FirstOrDefault(p => p.ID > 0); The SQL syntax that EF 5 prepares SELECT TOP (1) [Extent1].[ID] AS [ID], [Extent1].[DISTID] AS [DISTID], [Extent1].[SESSIONKEY] AS [SESSIONKEY], [Extent1].[NAME] AS [NAME], [Extent1].[PHONE] AS [PHONE], [Extent1].[EMAIL] AS [EMAIL], [Extent1].[CREATEUSER] AS

is it possible to share POCO object between two DbContext?

痴心易碎 提交于 2019-12-11 16:32:25
问题 I have some POCO classes which can generally divided into two groups, for example: public class Student { public Student() { this.Courses = new List<Course>(); this.Clubs = new List<Club>(); } public int Id { get; set; } public virtual ICollection<Course> Courses { get; set; } public virtual ICollection<Club> Clubs { get; set; } } and corresponding Course and Club classes, and they all have their own relationships to other classes. The problem is, those two groups are big, they both contains

Entity Framework does not pull through data from some columns

和自甴很熟 提交于 2019-12-11 13:53:41
问题 I have an issue where my entityframework model is not pulling though data from two columns of a sql server database table. It pulls through all the others but two integer columns are always zero regardless of what it says in the table. here are my two statements. statList = (from s in context.Stats where s.Make.ToUpper() == manufacturer.ToUpper() select s).ToList(); int i = (from d in context.Stats where d.StatID == 22 select d.ItemCount).FirstOrDefault(); The first statement obviously pulls

Selecting one bool column from another table

 ̄綄美尐妖づ 提交于 2019-12-11 13:17:06
问题 I have a successful query that returns multiple records from a joined table and also generates a bool Selected value (if a record exists for the current user in another table). public IEnumerable<BrowseVendorModel> SearchVendors(CustomSearchModel criteria) { var query = _db.VendorProfiles .Include("VendorCategories") .Include("VendorsSelected") .Select(s => new BrowseVendorModel { ProfileID = s.ProfileID, Name = s.Name, CompanyName = s.CompanyName, City = s.City, State = s.State, DateCreated