覆盖null的属性getter [英] Override property getter for nulls
问题描述
我正在使用带有现有sql server ce数据库的DbContext生成器(最终我希望相同的代码可以运行时可以根据sql server运行)。
I am using the DbContext generator with ef an exisiting sql server ce database (eventually I would like the same code to be runtime swichable run against sql server).
我想在可以为空的字符串属性上使用getter方法,以便在db包含null时返回一个emty字符串。 编写一个测试null的getter似乎很容易,如果为null则返回一个空格。 如果我更改生成的类
中的代码,如果我重新生成类,它将被覆盖。 我怎么能这样做?
I would like to have the getter methodss on the nullable string properties to return an emty string when the db contains null. It seems easy enough to write a getter that tests for null and returns a blank if null. If I change the code in the generated class, it will be overridden if I regenerate the classes. How can I do this?
推荐答案
你好CoolGuyStokes,
Hello CoolGuyStokes,
感谢你的帖子。
根据你的描述,我认为这个问题的讨论很好:
http://stackoverflow.com/questions/343211/blank-string-default-value-in-entity-framework-designer
According to your description, I think a good discussion about this issue is here: http://stackoverflow.com/questions/343211/blank-string-default-value-in-entity-framework-designer
您还可以在此主题中了解更多信息:
http://stackoverflow.com/questions/5836726/how-do-i-override-the-get-set-properties-of-a-field
You also can learn more in this thread: http://stackoverflow.com/questions/5836726/how-do-i-override-the-get-set-properties-of-a-field
我希望这对您有所帮助,如果我误解了您,请随时告诉我。
I hope this can help you, please feel free to tell me if I misunderstood you.
祝你有个愉快的一天,
这篇关于覆盖null的属性getter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!