entity-framework-5

Entity Framework Exception: Ambiguous match found

纵然是瞬间 提交于 2019-12-04 03:26:08
问题 I get the error: Ambiguous match found During this code on the .Add var db = new NexusEntities(); db.Reports.Add(mmr); From googling it appears to be an issue if the there are two classes with the same name but in different namespaces. As far as I can tell this is not the case... Is there another reason why this error can happen? Or is there a way to tell which parameter it is finding two of? 回答1: This is a "weakness" in EF. It happens when the same property appears in class / subtype

How to get the next Sequence number in Sql Server Express using Entity Framework?

六眼飞鱼酱① 提交于 2019-12-04 02:59:30
Now that Sql Server 2012 (including SQL Server Express 2012) has SEQUENCE feature just like Oracle as explained here , here , and here . I can get the next sequence like so, SELECT NEXT VALUE FOR SeqName But how do I do that from my code using Entity Framework 5? I got it working using SqlQuery like so.. int sequence = context.Database.SqlQuery<int>("SELECT NEXT VALUE FOR MySequenceName").FirstOrDefault(); 来源: https://stackoverflow.com/questions/16753149/how-to-get-the-next-sequence-number-in-sql-server-express-using-entity-framework

Entity framework manually deleted tables cant be generated from EF migration

混江龙づ霸主 提交于 2019-12-04 02:44:13
I have created migration and created the database and the tables . For example the tables are A B C D E . Now again I have changed some part of code and ran update-database command . Everything went smooth and nice and the tables showed the columns . Now accidentally I manually deleted one two tables D and E . Now when I try to run the migration with update-database . It runs properly but doesn't create the tables which I deleted manually . I tried to delete the existing migration and re-run update-database . It gives the error that apart from the two tables . There already an object existing

Is it possible to create a generic method for adding items to a entity framework dbset?

荒凉一梦 提交于 2019-12-04 02:32:22
I have not worked with Entity Framework or generics before and am having some difficulty reducing my code. I am parsing a text file to load 10 lookup tables with data that could possibly change nightly. The text files have a heading for the "type" followed by a list of key/value sets. I have this working perfectly, but I would like to refactor the code to clean it up and would like to use generic methods to accomplish this so I can reduce the duplicated code. I have gotten the parsing down to a generic method, but I have not been able to figure out how to get the entities added to the context

Entity Framework 5 - Enum based Discriminator for derived classes

人走茶凉 提交于 2019-12-04 02:14:39
I have the following (abbreviated for clarity) - an enum, a base class with that enum, and two derived classes that set the enum to a specific value. public enum MyEnum { Value1, Value2 } public class MyBaseClass { public MyEnum { get; protected set; } } public class DerivedOne: MyBaseClass { public DerivedOne { MyEnum = MyEnum.Value1; } } public class DerivedTwo: MyBaseClass { public DerivedTwo { MyEnum = MyEnum.Value2; } } What I want to do, is have Entity Framework 5 automatically distinguish between DerivedOne and DerivedTwo, with a MyEnum value based discriminator . I should be able to do

How should I disable Entity Framework table reference(foreign) list from each objects?

偶尔善良 提交于 2019-12-04 01:01:17
问题 I'm using Sqlite database and System.Data.SQLite 1.0.92 There is 2 table here: Table Person : PersonId PersonName Table Student : StudentId PersonId(reference table Person FK) StudentNo Now every time I get the Persons Collection in EF5: using (var ctx = new myEntities) { AllPersons = ctx.Persons.ToList(); } There is also has AllPersons.student collection will include in the result; But I don't need it. Of course that's just an example, There is a lot of big table has so many references, it

coordinateSystemId on DbGeography

微笑、不失礼 提交于 2019-12-04 00:52:03
I need to geocode a large number of addresses, using the Bing Map service, EF 5 and SQL Server 2008. I'm using the geography data type in SQL, which translates to a DbGeography type by the EF. When I create a DbGeography object, like this string point = string.Format("POINT({0} {1})",address.Longitude,address.Latitude); address.Location = System.Data.Spatial.DbGeography.PointFromText(point, 4326); The second parameter calls for a "coordinateSystemId". What exactly is this? A lot of the examples I see use 4326. I am new to spatial data, but I'm guessing there is a set of well defined coordinate

Why does EF 5.0 not support this EF 4.x LINQ syntax when compiling to sql?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 00:42:44
I have some code that was recently upgraded from EF 4.2 to EF 5.0 (actually EF 4.4 since I am running on .Net 4.0). I have discovered that I had to change the syntax of my query, and I'm curious as to why. Let me start off with the problem. I have an EventLog table that is populated by the client periodically. For each event log an entry is created in a Report table. This is the query that is run periodically to discover any event logs that do not have an entry in the Report table yet. The query I used in EF 4.2 was: from el in _repository.EventLogs where !_repository.Reports.Any(p => p

What is the reference for ´System.Data.Entity.Infrastructure´?

偶尔善良 提交于 2019-12-03 22:34:15
Using Entity Framework Power Tools Beta 2 extension , it generates model classes with the following imports: using System.Data.Entity.Infrastructure; What reference do I need to include into my project using Visual Studio 2010? Currently, I have the following References : log4net System.configuration System.Core System.Data System.Data.Entity System.Web System.Web.Mvc System.XML And in the Add Reference dialog I have the following: Don't add EF lib via "Add reference" dialog (it's old version) You need to add NuGet package "EntityFramework" of latest version. 来源: https://stackoverflow.com

Use Entity framework I want to include only first children objects and not child of child(sub of sub)

给你一囗甜甜゛ 提交于 2019-12-03 22:29:04
Useing Entity framework I want to include an only the first level of children objects and not the children of child I have these two classes: public class BusinessesTBL { public string ID { get; set; } public string FirstName { get; set; } public string lastName { get; set; } public ICollection<OffersTBL> OffersTBLs { get; set; } } public class OffersTBL { public int ID { get; set; } public string Name { get; set; } public int CatId { get; set; } public string BusinessesTBLID { get; set; } public virtual BusinessesTBL BusinessesTBLs { get; set; } } when I try to bring all offers according to