ADO.NET :: Would It Be Safe To Use Entity Framework Code First CTP5 In Public Release

Jan 18, 2011

Im a fan of the EF code first and with its last preview of the CTP5 I wonder if it would be safe for me to use this for a smaller site for customer? I would love to get your opinions on this? And any good sources for tutorials and information would be sweet. I'm currently reading the post on scottgu's blog about it.

View 1 Replies


Similar Messages:

Entity Framework CTP5 - Code First - Many To Many Relationship With Cascade Delete

Jan 4, 2011

I have two entities (Customer and CustomerRole) and would like to declare many-to-many relationship between them. I can do using the following code:

modelBuilder.Entity<CustomerRole>()
.HasMany(cr => cr.Customers)
.WithMany(c => c.CustomerRoles)
.Map(m => m.ToTable("Customer_CustomerRole_Mapping"));

But it creates the relationship (and the third mapping table) with cascade delete switched off by default. How can I tell EF to create the relationship with cascade delete switched on when using many-to-many?

View 1 Replies

Entity Framework CTP5 - Code First - Nested Query Error

Jan 3, 2011

I have the following classes:

public class Category
{
public int CategoryId { get; set; }
public string Name { get; set; }
}
public partial class CategoryMap : EntityTypeConfiguration<Category>
{
public CategoryMap()
{
this.HasKey(c => c.CategoryId);
this.Property(c => c.Name).IsRequired().HasMaxLength(400);
}
}
public class MyObjectContext : DbContext
{
public MyObjectContext(string connectionStringName)
: base(connectionStringName)
{
}
public DbSet<Category> Categories { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new CategoryMap());
base.OnModelCreating(modelBuilder);
}
}

Now when I run the following code I get an exception (GenericArguments[0], 'System.Int32', on 'System.Data.Entity.Internal.Linq.ReplacementDbQueryWrapper`1[TEntity]' violates the constraint of type 'TEntity')

DbDatabase.SetInitializer<MyObjectContext>(new DropCreateDatabaseIfModelChanges<MyObjectContext>());
using (var context = new MyObjectContext("NopSqlConnection"))
{
var query1 = from c in context.Categories
select c.CategoryId;
var test1 = query1.ToList(); //works fine
var query2 = from c in context.Categories
where query1.Contains(c.CategoryId)
orderby c.Name descending
select c;
var test2 = query2.ToList(); //throws the exception
}

View 1 Replies

Entity Framework 4 With Ctp5 And Dirty Generated Sql

Feb 3, 2011

I have a problem with strange generate sql in ef4 ctp5. I have simple model with mapping :

[Table("post_auction")]
public class PostAuction
{
[Key,Column(Name="Id"),DatabaseGenerated(System.ComponentModel.DataAnnotations.DatabaseGenerationOption.Identity)]
public int Id { get; set; }
[Column(Name = "Number")]
public int Number { get; set; }
[Column(Name = "Label")]
public string Label { get; set; }
[Column(Name = "Description")]
public string Description { get; set; }
[Column(Name = "CategoryId")]
public int PostAuctionCategoryId { get; set; }
[Column(Name = "PriceCZK")]
public int PriceCZK { get; set; }
[NotMapped]
public bool IsAuctionPhotoExitst
{
get
{
if (File.Exists(HttpContext.Current.Server.MapPath("~/Public/Images/Posts/Thumbs/small_" + this.Number + ".jpg")))
return true;
return false;
}
}
}

and my linq query is :...............

View 2 Replies

.net - The ODP.NET In ODAC 11.2 Release 3 (11.2.0.2.1) Already Supports Entity Framework (EF)?

Feb 1, 2011

The last release os ODP.NET already supports Entity Framework? Someone uses it? If the answer is YES.

View 2 Replies

Is It Safe To Use One Entity Framework Context Per Thread

Mar 30, 2011

Probably these are two questions in one, I am using one EF context per request, but I want to use one per thread, because I am going to make some complex task in another thread during the request. So, is it safe? If the answer is yes, how to do it? how to store objects in thread and get them back?

View 2 Replies

ADO.NET :: EF4 CTP5 Safe To Use?

Feb 28, 2011

I wonder if its safe to use the CTP5 in production yet. My main use would be for 2 small projects. I Know they pre released it but any thoughts on this if it would hold up for production are welcome.

View 1 Replies

Entity Framework - Is Using Public Static Variables For Compiled Queries Bad In Applications?

Aug 19, 2010

I'm coding a business layer for an ASP.NET application. I've created database methods in my BLL as static. I've created public static Func variables to be compiled and used in several different methods, like this:

namespace BLL
public class User
{
public static Func<Context, variable, result> selectUser;
private static void CompileQuery()
{
if(selectUser == null)
{
selectUser = CompiledQuery.Compile......
}
}
public static UserClass Select(int id)
{
CompileQuery();
//uses selectUser
}
public static SomethingElse DoSomethingElse()
{
CompileQuery();
//also uses selectUser
}
}

It'll be used in ASP.NET layer like this: using BLL;

private void AddUser()
{
UserClass user = User.Select(id);
}

My question is, since static variables are not thread-safe, is this a bad design decision? I'm thinking of either implementing a locking mechanism, which makes me think if it'd slow down the application, or using instantiated class approach which makes me wonder if query compiling would be beneficial.

View 1 Replies

Cast Exception When Try To Insert Entity In Entity Framework (using Code-f)

Feb 9, 2011

I get an cast exception when i am trying to insert an entity in Entity Framework (using code-first). From this code :

public virtual T Insert(T entity)
{
return Context.Set<T>().Add(entity);
}

The cast exception is like "impossible to cast ...Collection'1(Entity) to type (Entity)" I can't figure out why. I am pretty sure ive done everything right. Post entity

public class Post
{
public long PostId { get; private set; }
public DateTime date { get; set; }
[Required]
public string Subject { get; set; }
public User User { get; set; }
public Category Category { get; set; }
[Required]
public string Body { get; set; }
public virtual ICollection<Tag> Tags { get; private set; }
public Post()
{
Category = new Category();
if (Tags == null)
Tags = new Collection<Tag>();
}................................

View 9 Replies

ADO.NET :: Entity Framework Code First For Print Shop

Feb 14, 2011

I have a good friend who owns a print shop and he has asked me to create him a simple online shop where he can take print orders. His print shop location is kind of hidden, and business isn't going well at the moment. This is why he wants to move online. I said I would do it for him, but it will take a while before he has anything to look at. Where I am most stuck is the Model. The problem with this sorts of shops is that each Product, depending on its category would have different attributes. How ? Here is an example: [URL] A user would choose a product category, then he/she would get to the following: [URL] Now he/she would click the Order link to order a certain qunatity. On the next page, depending on what category they are in, they'll get a form where they can choose order attributes. There aren't many attribues for BUSINESS CARDS. But if they had chosen CARBONLESS FORMS, they would get options to tweak like: Squencial Numbering to start from 103490Position of Numbering..etc

I asked for advice at the SQL Server forums, and finally I came up with something like this:[URL] But with that database design, I will have a lot of type casting to do for the attributes ! << In fact I'm not sure if that would be even possible. Then I watched this video, and the author does something cool ! she uses Inheritance. Then I started Wonding ... Is it possible for me to have a Parent [ Product ] class, and have its children entities with different (added) attributes?

View 1 Replies

Perform Relationships In Entity Framework 4 Code-First CTP 5 ?

Jan 19, 2011

I would like to have a short example on how do you actually perform relationships in Entity Framework 4 Code-First CTP 5 ?

Would love an example for these kind of relations :

* one-to-many
* many-to-many

View 1 Replies

ADO.NET :: Cascade Delete - Same Table - Entity Framework 4 Code First

Feb 8, 2011

I been looking but I cant find any info on this topic Anyway I got a model that looks like this.

[Code]....

I want to cascade delete a category with all its sub categories but I cant make that reference in the database, not with the option to cascade update or delete. It work fine with pagecontents and all the other I got its just this same table reference. In NHibernate I do the cascade setting hbm or with a better way using the fluent option. How do I go about this task now?

View 1 Replies

MVC 3 Application Using Ninject, Entity Framework 4 Code-First CTP 5, Patterns

Jan 24, 2011

ive tried to build some base project with above technologies. I wanted maximum flexibility and testability so i tried to use patterns along the way to make this as a base for future projects. However, it seem.something is wrong or whatever and i really need help here. So

i have two questions :1- Is there anything wrong with my current code ? Ive applied patterns correctly ?

2- Why do this code actually connect to the database, create it, but doesnt support insert even if i perform the corrects operation ? (Look at the end of the post for details about this error)

I have two entities : Comment and Review

COMMENT [Code]....

REVIEW[Code].... I built up a base repository for each of them this way :GENERIC REPOSITORY[Code]...For specific operations, i use an interface :[Code]....So i am getting the generics operations from the abstract class plus the specific operations :[Code]....As you figured out, i also use a database factory will produce the database context :DATABASE FACTORY [Code]....DISPOSABLE (Some extensions methods...)[Code]....DATABASE [Code]....And to finish, i have my unit of work....UNIT OF WORK[Code]....I also binded using Ninject the interfaces :NINJECT CONTROLLER FACTORY [Code]....however, when i call in the constructor ...[Code]....

This seem to create the database but doesnt't insert anything in the database in EF4. It seem that i may figured out the problem.. while looking at the database object.. the connection state is closed and server version throw an exception of this kind :

ServerVersion = '(((System.Data.Entity.DbContext (_database)).Database.Connection).ServerVersion' threw an exception of type 'System.InvalidOperationException'

I am doing the right things ? Is there anything wrong in what ive built ? Also if you have recommandation about the code i posted, i would be glad. I am just trying to the learn the right way for building any kind of application in MVC 3. I want a good a start.

I use :
- Entity Framework 4 Code-First CTP 5
- ASP.NET MVC 3
- Ninject as DI Container

View 4 Replies

Exporting Entity Framework 4 Data Model To Entity Framework 3.5?

Oct 25, 2010

Is there a way to export a EF 4.0 Data Model to EF 3.5?

I looked around and found that we are not able to access EF 4.0 from a ASP.Net 3.5 project here: [URL]

Our project is the 1st to go to .Net 4.0 using Entity Framework and we (the team) were wondering if there was a way for the other projects that "might" need to access our data that are still using the .Net 3.5 framework.

View 1 Replies

ADO.NET :: Sample Code For A Login Control Talking To The Entity Framework

Sep 25, 2010

i have a web-site which uses forms based authentication. thus i have a login page with a login control on it. how would i go about coding the authenticate event of this control to talk to the Entity Framework to validate the user credentials?

View 2 Replies

Retrieving Data Is Slow Only When Use Entity Framework In The Code Page?

Aug 20, 2010

When I use classical ADO.NET or (which is interesting) EntityDataSource (e.g. for GridView), then page load within 1 second.But when I use ic codefile code like:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Cty = CType(Request.QueryString("cty"), Integer) ' course type
Page.SetFocus(ddl_FGPhotosOK)
If Not IsPostBack Then ' read course status
Using ctx_sdbEntities As New sdbEntities()
[code]...

View 2 Replies

C# - CTP5 EF Code / Getting Error

Mar 6, 2011

You can find the source code demonstrating this issue @ http://code.google.com/p/contactsctp5/

I have three model objects. Contact,ContactInfo,ContactInfoType. Where a contact has many contactinfo's and each contactinfo is a contactinfotype. Fairly simple I guess. The problem I'm running into is when I go to edit the contact object. I pulled it from my contact repository. Then I run "UpdateModel(contact);" and it updates the object with all the values from my form. (monitoring with debug) When I save the changes though, I get the following error:

The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.

It seems like after I call update model it nulls out my references and this seems to break everything?

Here are my models:

public partial class Contact {
public Contact() {
this.ContactInformation = new HashSet<ContactInformation>();
}
public int ContactId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<ContactInformation> ContactInformation { get; set; }
}
public partial class ContactInformation {
public int ContactInformationId { get; set; }
public int ContactId { get; set; }
public int ContactInfoTypeId { get; set; }
public string Information { get; set; }
public virtual Contact Contact { get; set; }
public virtual ContactInfoType ContactInfoType { get; set; }
}
public partial class ContactInfoType {
public ContactInfoType() {
this.ContactInformation = new HashSet<ContactInformation>();
}
public int ContactInfoTypeId { get; set; }
public string Type { get; set; }
public virtual ICollection<ContactInformation> ContactInformation { get; set; }
}

My Controller Action:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(Contact person) {
if (this.ModelState.IsValid) {
var contact = this.contactRepository.GetById(person.ContactId);
UpdateModel(contact);
this.contactRepository.Save();
TempData["message"] = "Contact Saved.";
return PartialView("Details", contact);
} else {
return PartialView(person);
}
}
Context Code:

protected override void OnModelCreating(System.Data.Entity.ModelConfiguration.ModelBuilder modelBuilder) {
modelBuilder.Entity<Contact>()
.HasMany(c => c.ContactInformation)
.WithRequired()
.HasForeignKey(c => c.ContactId);
modelBuilder.Entity<ContactInfoType>()
.HasMany(c => c.ContactInformation)
.WithRequired()
.HasForeignKey(c => c.ContactInfoTypeId);
}

View 2 Replies

How To Access A Module Or A Public Class With Public Shared Members From Inline Vb Code

Feb 10, 2011

I can access a module from code behind but not from the aspx page in inline VB code <% ... %>.

I know its got to be something simple but I can't seem to find the answer anywhere.

View 1 Replies

ADO.NET :: Entity Framework With Stored Procedure Versus Entity Framework Without Stored Procedures

Nov 2, 2010

I am new to entity framework , it is really very good , but I want to know what is the difference between using entity framework with stored procedure or without stored procedure , which one the faster and what is the benefits for using stored procedures with entity framework.

View 1 Replies

ADO.NET :: EF Code First CTP5 Not Generating The Database?

Jan 22, 2011

I've been using EF as my primary ORM for quiet some time now. Today I decided to use EF Code First to create my model for my new project. So I went ahead and read a bunch of documents on MSDN and some blog posts by Scott Guthrie and others. Unfortunately, what I've read does not go beyond the basics of using Code First within an ASP.NET MVC application. But as you might know, in real-world applications the structure of the solution is a little different. Anyway, to make a long story short:

- I created all the POCO files that will be needed.

- I created the SharweEntities class which extends the DbContext class.

- I added the following connection string to my Web.config file

[Code]....

Then I started the application and checked whether a new database was created inside SQL Server 2008 Express, but found nothing. I'm not sure what's wrong but I suspect it might be the way I'm structuring my solution? Here's the structure:

- Sharwe.MVC : The ASP.NET MVC3 Web Application (has nothing except a HomeController and a corresponding simple view at the time being)

- Sharwe.Data : model class and data access logic (contains all the POCO classes and the SharweEntities class)

- Sharwe.Services : Business logic

Here's an image that shows the structure of my solution:

View 3 Replies

Entity Framework -Update Entity When Another Entity Is Updated

Jun 30, 2010

I have an EDM, it includes the entities extension and history. My goal is to use history to keep track of all the changes made to extension entity. For example, if extension with ID 223 has its property 'Name_Display' changed - I want the history entity to record this.

I'm using ASP.NET with VB.NET. Where in my code do I put the hook to say, "update the history entity" and what should that hook look like?

View 1 Replies

MVC :: Display Lookup Field Using EF Code First CTP5?

Mar 7, 2011

I am hoping that people are not going to think it is too simple to bother with, because I am beyond stressed here..

I am trying to display a grid of Articles and their types using:
ASP.NET MVC 3
EF Code First CTP 5

The grid needs to look something like this:

TITLE TYPE
Roses Flower
Tables Furniture

what I need to change/add to the following

[Code]....

View 1 Replies

Visual Studio :: Determine What Namespaces Were Added With Which .net Framework Release?

Mar 5, 2010

I noticed when creating a reference that two of the columns in the dialog box under the .Net tab have Version and Runtime.

I'm assuming that Version is the version of the .Net Framework that a given namespace was introduced with.

I'm not sure I understand what the runtime is though. I originally thought it was for the version of ASP.net but now I question that. If look at two namespaces that were introduced with two different Versions they can have the same run time. This contradicts my original conclusion.

how these relate to each other and correct any misunderstandings I my have with this?

View 1 Replies

ADO.NET :: Entity Framework - Entity Stored Procedure Mapping - Can't Update

Feb 10, 2011

I am mapping a stored procedure to an entity by right clicking on the entity (in the .edmx) and selecting "Stored Procedure Mapping." This brings you to a Mapping Details - "Name of Entity" Window that allows you to select the insert, update, and delete stored procedures associated with the Entity. It also maps the stored procedure parameter to the Entity "Property" (Column).

I'm gettin an error "error 2042: Parameter Mapping specified is not valid." The cause of the error is fairly obvious, in the Insert stored procedure that has been selected, a 'CHAR' parameter is being mapped to an Int32 Entity Property. I altered the stored procedure parameter to match the entity, I deleted the stored procedure, readded, and reslected it as the Insert function. I also cleaned, validated, updated model from database. No matter what I do, the parameter list in the mapping details doesn't reflect the change to the stored procedure. It's stuck on a char --> int32 mapping, even though it has been changed, like it's buried deep in meta data some where.

View 2 Replies

ADO.NET :: Adding A New Entity In Entity Framework 3.5 With Related Data?

Aug 5, 2010

I am trying to add a new entity and have to refernce associated data to add it. I cannot load the Referencetables. Giving "The EntityReference could not be loaded because it is not attached to an ObjectContext." How do i complete this task in Entity Framework 3.5

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved