开发者

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

开发者 https://www.devze.com 2023-03-11 01:28 出处:网络
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:开发者_高级运维

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 D.B., use tools called "Object Relational Mapping" where you design an entity, and the program generates the C# (VB.NET) code and the S.Q.L. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号