entity-framework-5

Is there a better way to add a child record using MVC 4 and Entity Framework 5?

[亡魂溺海] 提交于 2019-12-05 15:54:38
I am just learning MVC and dealing with its stateless nature in combination with Entity Framework. My question is, is there a more elegant way of handling the scenario below? I have two POCO entities: public class Contest { public long ID { get; set; } .... ..... public ICollection<ContestPrize> Prizes { get; set; } } public class ContestPrize { public long ID { get; set; } public Contest Contest { get; set; } } I then have a MVC View that displays the Contest and all the Prizes associated with them. On that view I have a "Create Prize" link to create a new prize which passes the ID of the

coordinateSystemId on DbGeography

我怕爱的太早我们不能终老 提交于 2019-12-05 14:51:45
问题 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

Entity Framework 5 stopped running T4 templates files on save

喜欢而已 提交于 2019-12-05 13:08:52
At work we just upgraded to Entity Framework 5. Our EDMX file now has a couple other nodes beneath it: EntityContainer.Context.tt which contains the generated DbContext object and EntityContainer.tt which contains the entities themselves. For a short period, adding an entity in EF was automatically regenerating the tt (T4 Templates) when we would save the EDMX file. Now all of a sudden we have to right-click the T4 templates and select "Run Custom Tool" to get them to regenerate the .cs files for the context or entities. Any ideas how this might have happened? Update In the EDMX the property

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

我们两清 提交于 2019-12-05 12:52:18
问题 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: 回答1: Don't add EF lib via "Add reference" dialog (it's old

Log4net with Entity Framework 5 and MVC4

笑着哭i 提交于 2019-12-05 12:02:45
So I am starting this new project and want to use Log4net to log to the Database. I am using EF for other things and it connects fine. For some reason L4N is not logging anything but not throwing any errors. Just wondering what step(s) I may be missing, hope someone can point it out. Do I need to "save" to the db somehow? Thanx so much in advance. My web.config: <log4net> <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"> <bufferSize value="100" /> <connectionType value="System.Data.EntityClient.SqlConnection, System.Data, Version=1.0.3300.0, Culture=neutral,

Using ToString() in LINQ queries?

大兔子大兔子 提交于 2019-12-05 11:15:56
I have writting a LINQ query to fill a listview but it useses the .ToString() method which apparetly is not allowed. When I use the below code I get the error message: Error: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression Is there a way to use the ToString() in LINQ or if that is not possible what is the solution to converting a DateTime to String in the query. Please knot that ReleaseDateName is a string and ReleaseDate is a DateTime using (var db = new ReleaseInfo()) { lvReleaseInfo.DataSource =

Entity Framework Code First - How to ignore a column when saving

折月煮酒 提交于 2019-12-05 10:56:53
I have a class called Client mapped to a database table using Entity Framework code first. The table has a computed field that I need available in my Client class, but I understand that it won't be possible to write to this field. Is there a way of configuring Entity Framework to ignore the property when saving, but include the property when reading? I have tried using the Ignore method in my configuration class, or using the [NotMapped] attribute, but these prevent the property from being read from the database. You can use DatabaseGeneratedAttribute with DatabaseGeneratedOption.Computed

How to define a custom naming convention if EF 5

若如初见. 提交于 2019-12-05 10:45:09
Suppose that I have a database with 1 table named Products . So, I go through the Db First approach and create an EF model in VS 2012 with pluralize and singularize option. So, the model creates a Product entity for me, and default naming convention maps this entity to the dbo.Products table. Now I want to change this behavior. In fact I want to create a custom convention to map ProductModel entity to the dbo.Products table. Is this possible?! If so, how? Update: My goal to do it... As you know, whenever you update your model from database, if it causes a change in your model, the auto

The value “(string)” is invalid

倾然丶 夕夏残阳落幕 提交于 2019-12-05 10:32:02
I currently have a view that contains two text boxes where users can enter in some data. One text box only allows values of 1-10, the other a string. I am not sure what code change I made, but the second text box accepting a string no longer "works". For example, when I enter in a string and try to submit the form, I get a validation message that states "The value "(string)" is invalid. Below are some code snippets in my solution. Entity: public class MovieReview { public int Id { get; set; } [Range(1, 10)] [Required] public int Rating { get; set; } public string Review { get; set; } public

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

我的未来我决定 提交于 2019-12-05 09:59:28
问题 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; }