简体   繁体   中英

Using attributes to serialize generic insert, update, etc. statements?

Before I go run off creating my own attributes and the such, is there anything already out there that would let me do something like the following:

[SomeAttribute(TableName = "persons")
public class Person
{
    [SomeMemberAttribute("first_name")]
    public String FirstName { get; set; }

    // etc...
}

so that I can use those attributes to generate SQL Insert, Update, etc statements and also to deserialize a datareader into the object?

Have you checked out the Code first Entity Framework (AKA Magic Unicorn). Microsoft is developing it, and I've heard really great things. Here's Scott Gu's thoughts:

http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

also, here is the home page for the ADO.NET entity framework:

http://msdn.microsoft.com/en-us/data/aa937723

The previous answers mention that maybe your version of ".Net" may have some tools to handle what you want, including the ADO.NET entity framework.

There are other ways to work with Entity or Business Objects, in case you have an earlier version of Visual Studio.Net, or want to develop you application in a different way.

Many developers instead of coding an object directly in C#, or writing the code from an existing table in a DB, use tools called "Object Relational Mapping" where you design an entity, and the program generates the C# (VB.NET) code and the SQL commands you need it.

You may want to search on the internet about those tools, instead of the using the attributes you mention, because if you need to change your entity both in C# or table, adding or removing fields, the O.R.M. tools generates the code easily, and coding "by hand", its more difficult.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM