poco

EF CodeFirst: Get all POCO types for DbContext

旧城冷巷雨未停 提交于 2019-12-03 13:16:32
Is there any way to get POCO's types from specified DbContext instance? You need to access the MetadataWorkspace public class MyContext : DbContext { public void Test() { var objectContext = ((IObjectContextAdapter)this).ObjectContext; var mdw = objectContext.MetadataWorkspace; var items = mdw.GetItems<EntityType>(DataSpace.CSpace); foreach (var i in items) { Console.WriteLine("Class Name: {0}", i.Name); } } @Lei Yang: you can use this to get all types into a list. var objectContext = ((IObjectContextAdapter) dbContext).ObjectContext; var mdw = objectContext.MetadataWorkspace; var items = mdw

What are essential differences between the different code generation items for EDMX model?

戏子无情 提交于 2019-12-03 12:02:00
I'm trying to ramp up on the entity framework so I don't feel like I'm in the dark ages. I tried (and have thus far failed) to intuit from generated code what the essential differences between the available code generation items. It seems POCO isolates the entity data structures from the ojbect that moves them in/out of a datastore. I'm not sure what a "Self-Tracking Entity" is. I'm guessing the tracking part refers realizing the so called "unit of work" pattern, but I'm not posative. And more head scratchingly, I guess I'm wondering "self tracking as opposed to what?". Ladislav Mrnka POCO

How to statically link using link.exe

前提是你 提交于 2019-12-03 11:25:34
问题 I've been trying to statically link against a C++ library called Poco on Windows using the Visual Studio 2008 command line tools. I build my program with: cl /I..\poco\lib /c myapp.cpp link /libpath:..\poco\lib myapp.obj PocoNet.lib This results in an exe that at runtime requires PocoNet.dll and PocoFoundation.dll. I spent some time reading up on linking in Windows, and learned that cl /MT statically links against the standard library, while cl /MD links dynamically. I tried to specify /MT ,

Fast serialization and deserialization using dynamically emitted POCOs

≡放荡痞女 提交于 2019-12-03 11:17:25
问题 I am currently serializing SQL table rows into a binary format for efficient storage. I serialize/deserialize the binary data into a List<object> per row. I'm trying to upgrade this to use POCOs, that will be dynamically generated (emitted) with one Field per column. I've been searching online for hours and have stumbled upon ORMs/frameworks like EF, T4, ExpandoObject, but all of these either use a dynamic object (properties can be added/removed on the fly) or simply generate a POCO before

Entity framework attach update not working

懵懂的女人 提交于 2019-12-03 10:36:55
I'm trying to update a POCO object using entity framework in the following way: context.Jobs.Attach(job); context.SaveChanges(); That does not work. No error is thrown, it just isn't updating the values in the database. I tried: context.Jobs.AttachTo("Jobs", job); context.SaveChanges(); Nothing wrongs, still no error and no updates. What about changing the ObjectState ? context.ObjectStateManager.ChangeObjectState(job, System.Data.EntityState.Modified); From MSDN: ObjectStateManager.ChangeObjectState Method . Ladislav Mrnka I guess you are working with detached object - check second part of

Exception during association fixup with nullable composite foreign keys

雨燕双飞 提交于 2019-12-03 08:29:46
I have a problem with Pocos and nullable foreign keys . I have 2 tables (orders and products) each table have a composite primary key (orderid,orderid2) and (productid,productid2) And I have set a 0,1..* association between the two tables. One order can be related to 0 or 1 product. And one product has * orders related to him. How to crash : Create a new product using CreateObject(). Add the new product to then entityset. Create a new order usung CreateObject(). Add the new Order to the entityset. When I add an order to the product's orders list, it crashes trying to fixup the association

Using Data Annotations on POCO's with MVC for Remote Validation

泄露秘密 提交于 2019-12-03 08:02:17
I am developing an ASP.NET MVC app and I've been looking into using Data Annotations on my POCO's which are defined in my Service Layer. As long as I have a reference to System.ComponentModel & System.ComponentModel.DataAnnotations this is no problem and what I like about this is that it allows me to reuse my Service Layer in a Win Forms app. I'm now looking to do some Remote Validation using Data Annotations and have taken a look at this article: http://msdn.microsoft.com/en-us/library/ff398048(VS.100).aspx However, to use the Data Annotations in this context I need to reference System.Web

In a layered architecture using Entity Framework, should I return POCO classes from the BLL? (Architecture guidance needed)

梦想与她 提交于 2019-12-03 06:53:17
I've been reading too much probably and am suffering from some information overload. So I would appreciate some explicit guidance. From what I've gathered, I can use VS2010's T4 template thingy to generate POCO classes that aren't tied directly to the EF. I would place these in their own project while my DAL would have an ObjectContext-derived class, right? Once I have these classes, is it acceptable practice to use them in the UI layer? That is, say one of the generated classes is BookInfo that holds stuff about books for a public library (Title, edition, pages, summary etc.). My BLL would

Best Practices for Lookup Tables in EF Code-First

旧城冷巷雨未停 提交于 2019-12-03 06:05:01
问题 I'm doing my first project with EF and I'm planning to go the code-first model. I'm trying to find a bit of guidance about handling a fairly classic "lookup table" scenario. I'm dealing with a pretty canonical situation where I'll be persisting address data. So, I have a simple address DTO... public class Address { public int Id { get; set; } public virtual string StreetAddress1 { get; set; } public virtual string StreetAddress2 { get; set; } public virtual string City { get; set; } public

Are code generators bad?

点点圈 提交于 2019-12-03 05:11:22
I use MyGeneration along with nHibernate to create the basic POCO objects and XML mapping files. I have heard some people say they think code generators are not a good idea. What is the current best thinking? Is it just that code generation is bad when it generates thousands of lines of not understandable code? ConcernedOfTunbridgeWells Code generated by a code-generator should not (as a generalisation) be used in a situation where it is subsequently edited by human intervention. Some systems such the wizards on various incarnations of Visual C++ generated code that the programmer was then