entity-framework-4

Entity Framework with MYSql, return no column in complex entity return type

折月煮酒 提交于 2019-12-07 08:45:54
问题 I'm using MySQL in combination with an edmx file. I'm facing a problem when adding a function to stored procedure. When I select "complex type" and press the "get column information" button I receive the following message: "The selected stored procedure returns no columns." When I create the same procedure in SQL Server and then added the function to a new edmx file, its creating the complex type perfectly. Thanks, Nauman 来源: https://stackoverflow.com/questions/9940749/entity-framework-with

Entity Framework Insert object with related object

浪尽此生 提交于 2019-12-07 08:44:46
问题 I am a newbie with Entity Framework and I need to insert an object Comment that has a related FK object User into the database. public Class Comment { public int CommentID { get; set; } public string CommentContent { get; set; } public virtual User User { get; set; } public virtual DateTime CommentCreationTime { get; set; } } public class User { public int UserID { get; set; } public string UserName { get; set; } public string UserPassword { get; set; } public string UserImageUrl{get; set;}

Entity Framework 4 - TPT Inheritance in Features CTP5 (code first): rename foreign key column on inherited table

ぐ巨炮叔叔 提交于 2019-12-07 08:14:32
I'm trying to convert an xml Entity Framework model to Code First (CTP5) one. I have to model a hierarchy which fits quite well the TPT pattern. The only problem I have is that the primary key/foreign key of the "inheriting" table has a different name from the primary key of the base class. These are the relevant fields of the involved tables CREATE TABLE site.Domains ( ID INT NOT NULL PRIMARY KEY, Domain NVARCHAR(128) NOT NULL ) CREATE TABLE site.MainSites ( FKDomainID INT NOT NULL PRIMARY KEY REFERENCES site.Domains(ID) ) CREATE TABLE site.SisterSites ( FKDomainID INT NOT NULL PRIMARY KEY

Entity Framework 4 very slow linking an Order to Customer who has 10,000 orders

喜夏-厌秋 提交于 2019-12-07 07:56:50
问题 This one has me stumped. I have a Customer and Order entity. the Customer can have many Orders. Where the Customer has 10,000 orders when I create a new Order and set the Customer property (Order.Customer = customer) there is a LONG delay (20s of seconds). It appears that the context is loading all 10,000 orders before adding this new one. I am not currently using FKs directly which I suspect may help. Any ideas how I can improve matters without a massive refactor? Cheers. 回答1: The problem is

Cannot Insert custom value into identity column - Entity Framework

大兔子大兔子 提交于 2019-12-07 06:47:51
问题 I am trying to switch the identity off to insert my own value, steps I followed changed the property StoredGeneratedPattern value to None for the identity column changed the property StoredGeneratedPattern value to None in EDMX file by opening in xml format Tried using the below code using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { int k = Context.ExecuteStoreCommand("SET IDENTITY_INSERT dbo.client ON"); Context.ClientInfoes.Add(testclient); result =

ExecuteStoreQuery with TVP parameters

≯℡__Kan透↙ 提交于 2019-12-07 06:30:17
问题 I have a stored procedure in my database that takes a table value parameter, a list of IdTable objects which contain a single integer Id column. I have an entity model for the database and want to do the following... ProjectEntities projectEntities = new ProjectEntities (); DataTable stationIds = new DataTable(); stationIds.Columns.Add("Id"); stationIds.Rows.Add(1); stationIds.Rows.Add(2); SqlParameter parameter = new SqlParameter("@stationIds",stationIds); parameter.TypeName = "IdTable"; var

Mapping composite foreign keys in a many-many relationship in Entity Framework

你说的曾经没有我的故事 提交于 2019-12-07 06:02:57
问题 I have a Page table and a View table. There is a many-many relationship between these two via a PageView table. Unfortunately all of these tables need to have composite keys (for business reasons). Page has a primary key of (PageCode, Version), View has a primary key of (ViewCode, Version). PageView obviously enough has PageCode, ViewCode, and Version. The FK to Page is (PageCode, Version) and the FK to View is (ViewCode, Version) Makes sense and works, but when I try to map this in Entity

AllowHtml attribute on EntityFramework class

♀尐吖头ヾ 提交于 2019-12-07 05:02:43
问题 Is there a different way of setting the [AllowHtml] attribute on a property of a class that is being auto-generated by EntityFramework? I hate changing the autogenerated files because every time I make a change to the model, my changes get lost. But there is no other obvious way for setting [AllowHtml] for a specific property other than by using the attribute. Is there a non-attribute way of doing it? 回答1: You can use the MetadataTypeAttribute to specify attributes for the generated code in

Entity Framework CTP4 Code First: Mapping protected properties

霸气de小男生 提交于 2019-12-07 04:23:14
问题 I would like to use a lazy-loading collection on a model, but I want Add/Remove functionality to be done through separate methods. So something like this: class Model { protected virtual ICollection<Something> _somethings { get; set; } public IEnumerable<Something> Somethings { get { return _somethings; } } public void AddSomething(Something thingToAdd) { /* logic */ _somethings.Add(thingToAdd); } } I can't figure out how to configure the mapping for this. I looked into using a configuration

Many queries and too much opening / closing of the same connection

只谈情不闲聊 提交于 2019-12-07 04:11:25
问题 I have to recalculate values on a large collection of entities, one after the other. During that process, all the self-tracking-entities are altered within the same ObjectContext. For each entity that needs to be processed, small amounts of data has to be fetched from the database. That results in a lot of the same SQL query but using different parameters. I am using Solutions Design's ORM Profiler software to profile the queries that are sent to the database. The queries themselves seems